Adding a simple text clock to a Form

Diversion

Dutch Databaser
Local time
Tomorrow, 00:37
Joined
Apr 13, 2005
Messages
16
Trying to make a simple clock inside my form.
So far I got my clock but it isn't running.
It only get's the time when I open the form but I want it to keep track of time.

Searched the forums but couldn't find anything that relates to this problem.
 
You need to set a timer on your form, and when the timer event fires, update your clock.
 
But how do I set the timer to let it update every second?
I'm new to the timer part...
 
Why waste processor time with this? Most screens will have a clock in the bottom right hand corner if the Windows system tray - is there really a need, other than aesthetics, for having two clocks on the one screen?
 
It isn't really a must , but it just made my form look a lot more proffesional :D
 
Diversion said:
but it just made my form look a lot more proffesional :D

Believe me, it probably hasn't. It's probably went in the other direction.

Anyway, you set the form's TimerInterval property to 1000

You set the time event to:

Code:
Private Sub Form_Timer()
    Me.MyLabel.Caption = Now()
End Sub
 
If your going to put a clock on a form, you are better of not displaying seconds. And just having it update every 15 seconds so you aren't wasting to many cpu cycles.
 
here you go buddy... just follow the instructions below :

1.Make a label named as - lblClock
2.Set your form's Time Interval (found in the Form properties) to 1000

3.Put the following VB code into your forms VB.. dont mess, just add it exactl as it is:

Code:
 Private Sub Form_Timer()
Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm:ss AMPM")
End Sub

AND there you have it, the clock WILL UPDATE automatically... ;) enjoy
 
The timer is not an interrupt service; it behaves as a very low priority polled service when Access has nothing better to do.

The timer is serviced no more frequently than 1 (one) millisecond.
In that time frame a modern processor (1 GHz) would have spun 1 (one) million CPU cycles simply looking for something to do.

If Access has something better to do then it will do it and the timer call will be delayed.

That is the reason for often posted questions about ‘update events on timer don’t get updated during heavy processing’…
Access does not yield to the timer without force. (DoEvents)

Screen aesthetics is another thing entirely.

It may be better to display the long date/time for whatever reason.
The reason for doing so can only be decided when the application is understood.

There may be other considerations invoked here, such as network loading or screen flicker, but the local machine should not suffer the consequences of any timer setting.

The event will simply be done when the local machine has time to do it, and not before.

Regards,
Chris.
 
The code mentioned above works perfectly for me, even at heavy CPU processing.
 

Users who are viewing this thread

Back
Top Bottom