Display time on form, add current time data

S

SandyB

I want to create a uneditable field (label?) on a form
that will display the current time - obviously refreshing
more than once a minute. I also have begin and end time
fields that I would like to insert the current time on
double click, for example. I would also like to
automatically calculate time elapsed (also on double
click?) in another field. Thanks for your help!
 
M

Marshall Barton

SandyB said:
I want to create a uneditable field (label?) on a form
that will display the current time - obviously refreshing
more than once a minute. I also have begin and end time
fields that I would like to insert the current time on
double click, for example. I would also like to
automatically calculate time elapsed (also on double
click?) in another field. Thanks for your help!


Use the form's Load (or other appropriate) event to set the
start time:

Me.txtStartTime = Now()
Me.TimerInterval = 250 'milliseconds

Use the form's Timer event to update the "clock" text box.

Me.txtCurrentTime = Now()

The double click thingy can the do calculation something
like this:

Me.TimerInterval = 0 'turn timer off
Me.txtEndTime = Now()
lngElapsedSeconds = DateDiff("s", Me.txtEndTime,
Me.txtStartTime)
lngHours = lngElapsedSeconds \ 3600
lngMinutes = (lngElapsedSeconds - 3600 * lngHours) \ 60
Me.ElapsedTime = lngHours & Format(lngMinutes, "\:00") _
Format(lngElapsedSeconds Mod 60, "\:00")

NOTE: be sure to close this form before trying to edit any
module, the timer can seriously interfere with the code
editor.
 
Top