Results 1 to 7 of 7
  1. #1
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127

    Lightbulb parsing for addition

    Hello people of Access Forums! In my report, i have a column where all of the hours a person has worked are recorded in the format of # Hours, # Minutes.

    At the very bottom of this page, I have a box which I want to take the numbers (#) from the above mentioned format and add them together to get a total time spent. EX: 4 Hours, 7 Minutes + 3 Hours, 33 Minutes = Total Hours: 7 Hours, 40 Minutes

    I need to parse the information from the Hours Worked field that is already there because it is in the string format from some code i had done a long time ago. What I believe is needed is for the value of hours to be parsed going down the entire report to be added together and output in the Total Hours box. it would also be for the best for the amount of minutes to be added together and that when they reach 60, to be added as a plus one to the total hours.

    This has been a recurring problem for me and I would really like to just get rid of it as fast as i can.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I think you want a function that operates on each record and converts to a common denominator (seconds, minutes, etc). The basic tools you'll need are the Split() and Val() functions. It won't be too difficult if each record has the same sections (hours, minutes). It will be trickier if a record might just have minutes or something like that. Your other post said these contained seconds, so you'll want to clarify that too.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Use string manipulation functions in expressions in query.

    This will return the hours, assumes there will always be an hours part, even if 0 Hours.
    Val([fieldname]) As HoursWork

    The minutes are trickier, again assumes minutes part exists, even if 0 Minutes.
    Val(Mid([fieldname], InStr([fieldname],",")+2) As MinutesWork

    Refer to these constructed fields in report to do summary calcs.

    Divide minutes by 60 to get decimal hours. All in one field would be like:

    Val([fieldname]) + Val(Mid([fieldname], InStr([fieldname],",")+2)/60 As TimeWork
    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.

  4. #4
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    If Val returns the numbers in a data field, since mine is 4 hours, 7 minutes, wouldn't it return the 4 AND the 7?

    Also, how would i be able to make my one text box in my report actually add together ALL of the total hours and minutes worked?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Val stops when it encounters non-numeric values, so it returns 4 for the hours. You can test functions in the Immediate window of the VBA editor.

    Use the constructed field in aggregate calc in textbox in group and/or report footer.
    Sum([TimeWork])
    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.

  6. #6
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    so since the field the times will be coming from is called Hours_Work, how would i save each of those times as a variable to be added by Sum([TimeWork]) because I'm assuming the Sum([TimeWork]) is what will be in the Total Time text box.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    You create a field in query using suggested expression. That constructed field can be referenced by form or report just like any field. Access query designer will assign a name to the constructed field, like Expr1. You can replace that with anything you like.

    Access Help has guidelines on building queries with calculations. Access2010 has a new datatype for tables - Calculated.
    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.

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

Similar Threads

  1. XML Parsing Error
    By pb45102 in forum Access
    Replies: 2
    Last Post: 09-11-2011, 10:20 PM
  2. Combo box-Selective addition
    By reidn in forum Forms
    Replies: 1
    Last Post: 07-20-2011, 11:44 AM
  3. Parsing for data in between two characters
    By rawdata in forum Access
    Replies: 7
    Last Post: 11-02-2009, 04:46 AM
  4. Parsing data into something usable.
    By crownedzero in forum Import/Export Data
    Replies: 22
    Last Post: 08-05-2009, 07:18 AM
  5. addition with 0
    By Peljo in forum Access
    Replies: 0
    Last Post: 02-28-2008, 08:12 PM

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