Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Location
    Cinci, OH
    Posts
    49

    Unanswered: subtracting time entered on time sheet

    hey all,

    Hope you can help.

    I am trying to get the total number of hours worked on a time sheet form

    We have the txtTimeStart (day start), txtTimeOut (lunch start), txtTimeIn (lunch end), and txtTimeEnd (day end)

    The calculation will end up in txtTIMETOTALS.

    These are in the table as date/time and are in shorttime format.

    This is the code I have written:

    Private Sub txtTimeEnd_AfterUpdate()
    'this will take the times entered by tech and total the hours for the day
    'on close this number will be used in a comparison with the total hours worked
    'to make sure the they match and the info entered is accurate


    'set total time to zero
    timetotal = 0

    'Calculate total hours for day
    timeday = 0
    timeday = txtTimeEnd - txtTimeStart

    'Calculate time away at lunch
    timelunch = 0
    timelunch = txtTimeIN - txtTimeOut

    'Calculate total hours worked for the day
    'TimeDay - TimeLunch = TimeTotal
    timetotal = timeday - timelunch
    txtTIMETOTALS = timetotal

    End Sub

    When I enter the following values:

    TimeStart = 7:30
    TimeOut = 12:00
    TimeIn = 13:00
    TimeEnd = 16:30

    the result I get in txtTIMETOTALS = 0.33

    Somthing I am doing is not right.

    Hope someone can help me out.

    Thanks very much for any and all input.

    Happy Superbowl weekend

    Richard
    aka
    rmousir

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Try using datediff instead. Either that or parse out the hours/minutes specifically.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    "Somthing I am doing is not right."
    your overall time is 8 hours in the example you give.
    8/24 = 0.333333r
    ...that's how A stores times.

    you have a display format problem.

    meanwhile Teddy is right: datediff is safer.
    your current mechanism implodes if a time interval includes midnight.

    izy
    currently using SS 2008R2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •