Results 1 to 14 of 14
  1. #1
    jinro is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    12

    Converting minutes into hours in report

    Hey there all,

    I have a tracking database I have been working on and so close of being done just held up on this last part. What I am trying to do is have the totals = Ex. 1.25 + 3.50 would give Grand total of 5.15 not 4.75. The table has a field called time spent which stores the time. I have attached an example database. So whenever the minutes = more then 60 for it to add 1 to the hour.


    Thanks for any help and your time.
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Are you saying that the 75 is 75 minutes and not .75 (45 minutes) of an hour? That really looks like decimal hours. How did you calculate the values of 1.25 and 3.50?

    To convert decimal hours to HH:MM, try:

    x represents the decimal hours value of 4.75

    Int(x) & ":" & (x - Int(x)) * 60

    I tried to open your db but Access 2007 does not recognize it. Must be a 2010 or 2013 version. If you still have issue with this calc, I can try with 2010 later.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Actually, the grand total would be 5:15 (5 hours and 15 minutes). 1.25 + 3.5 = 4.75 = 5.15

    Here is a function to do the conversion:
    Code:
    Private Function Convert2HrsMIns(sHrsMin As Single) As String
       Dim x As Single
       Dim M As Single
       Dim rM As Single
    
       Dim H As Integer
       Dim rH As Integer
    
       x = sHrsMin   'orig number
       H = Int(x)  'hours part
       M = (x - H) * 100   '  minutes part
       rH = M \ 60  ' integer division - hours in the minutes
       rM = (M Mod 60) / 100   '  remainder (minutes)
    
       Convert2HrsMIns = H + rH + rM
    
    End Function

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not if the .75 is a decimal hour (i.e. 75/100ths of an hour) - 0.75 hour is 45 minutes.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    jinro is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    12
    Yes 5.15, ive been banging my head all day so miss typed. So that code I just paste it in the module then what?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Call the function:

    from query

    CalcHours: Convert2HrsMIns([fieldname])

    or

    textbox:

    =Convert2HrsMIns([fieldname])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    jinro is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    12
    When i try as query I get error undefined function "Convert2HrsMIns" in expression.
    When I try as textbox It pops up a window box that says Convert2HrsMIns and is acting like it wants me to type something in, when i click nothing or even put something in it just says error.
    I must be doing something wrong, i feel like im so close. Thanks for your guys help and time btw. trying to tinker with it still as we speak

    btw i attached an .mdb version this time since you said you could not open the last one. Maybe if you saw what I am might help
    Attached Files Attached Files

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    That file is named: Sample.mdb.accdb

    Can't open that one either.

    To use in query the function must be in a general module.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    jinro is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    12
    "smacks self on head" i should of had a V8... sorry had extensions turned off, this one is correct .mdb

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Sorry, Access 2007 still says unrecognized format. I will double check with 2010 later.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    jinro is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    12
    ok thanks, i attached one last time i just created a brand new access in .mdb on top it now says 2002-2003 file format. the other said 2007-2010. If you dont have time to try again i understand and I already appreciate all the time you have put in to this problem for me.

  12. #12
    jinro is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    12

    this is good file

    =/ if you were able to open it, it was messed up dragging the files right over messed it up.. attached is good ones had to rebuild the query pulling over killed it.
    Attached Files Attached Files

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You don't want to use it in that query because it is not summing the time data.

    The function needs to be declared Public or leave off 'Public' and it will default as Public but 'Private' prevents other modules from seeing the function.

    Then call the function in report textboxes:

    =Convert2HrsMIns(Sum([time spent]))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    jinro is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    12
    YAYYYYYYY!!!!!!!!!!!! "bows and bows a zillion times"
    thats it got it...THANK YOUS SOOOOOO MUCH, I CAN FINALLY SLEEP!!!! =) thank you sooo much

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Field to display hours and minutes
    By burrina in forum Forms
    Replies: 5
    Last Post: 01-19-2013, 05:35 PM
  2. formating hours and minutes to 0.00 format
    By live2ride in forum Access
    Replies: 17
    Last Post: 09-18-2012, 07:52 PM
  3. Converting Minutes Into Hours
    By KellyM in forum Reports
    Replies: 8
    Last Post: 04-23-2012, 12:49 PM
  4. Overall Total of Hours & Minutes in Report
    By StevenCV in forum Reports
    Replies: 1
    Last Post: 02-27-2012, 10:48 AM
  5. How to calculate duration in hours & minutes
    By joypanattil in forum Access
    Replies: 0
    Last Post: 11-25-2009, 04:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums