Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate time differences with a twist

Status
Not open for further replies.
Apr 19, 2000
73
0
0
US
I have a subform with the following fields
Time in - format as short time (12:00 AM)
Time out - format as short time (12:00 AM)
Hours - format as a number (2 decimal places)

I need to calculate the difference between Time in and Time out and then populate the Hours field after the user updates the time out field.

The twist is that I need the Hours field to be a number and to calculate the time in tenths of an hour (example: Time in is 1:00 PM and TIme out is 2:30 PM so hours would be 1.5)




 
ControlSource for calculated control: =([timeout] - [timein])*24
Format for calculated control: Fixed or General Number
Decimal Places for calculated control: 2

To populate hours field, use a macro with setvalue or:

1. Have a second control that is invisible for the storing of the hours value.
2. In the afterupdate of timeout have the following code:

If IsNothing(timein) or IsNothing(timeout) then
MsgBox("You must enter both an in and an out time.")
timein.SetFocus
Else
hours = txthoursdisplay
End If


Best regards,
SATHandle

:)

Don't beat your head against the wall unless you know how to plaster.
 
I do somethig simmilar for hour
calculating it in the SQL of the record source of the form

ProductionHours: (DateDiff("n",[Labour]![StartTime],[Labour]![EndTime]))/60

replace starttime and endtime with your
Time in
Time out

and Labour is the name of my table
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top