Adding in a clock or the correct time

A

alexr114

Is there a way to add a clock or the time into a form. I have found the way
to add the time the form was accessed at but not a fully changing one.

Thanks
 
B

Ben

Hi Alex,

You can do this with the OnTimer event on the form.

1. Create a textbox called txtClock. Set it's data Enabled property to No
and it's Locked property to Yes.
2. Set the TimerInterval property of the form to 1000 (1 second updates)
3. Use the following code in the OnTimer event.

Private Sub Form_Timer()
Me.txtClock = Format(Now(), "hh:mm:ss")
End Sub

Voila!

Ben.
 
A

Al Camp

Alex,
Ben and Ofer are correct, but I'd like to add just a bit to their solution...

Consider using a 60000 interval that causes the clock to increment every minute, rather
than every second.
Usually, there's really no need to display incrementing seconds. It can be a bit
distracting on the form, and if a user does need to enter the exact date and time, that
can be done programatically. (not the user looking up at the time an then entering it)

Al Camp
 
A

Al Camp

Ben,
Well... just a bit.
Actually, doing a clock is fun, and an easy way to learn about timer events and intervals.
We all did it, and then said, "Ooo... that's cool!" :-D
But... then we don't ever really use it on a form...
Al Camp
 
Top