access 2010 - time function

phillbaker

Registered User.
Local time
Today, 13:44
Joined
Jun 29, 2008
Messages
45
i have tried adding a label to a form and putting some vbcode in so that instead of the time being static it updates it like a real time clock. I put this in the ontimer event in the form and set the number of seconds but the form is not displaying the clock.

is there something im missing over something really simple or has the way in access 2010 been changed.
 
Okay, first - if you use a label the code has to change the CAPTION property.

Second, the timer interval needs to be 1000 (1000 is the equivalent of 1 second).

Third, the form's timer event would look like this:
Code:
Private Sub Form_Timer()
  Me.YourLabelControl.Caption = Now
End Sub

So, do you have that set up?

If so and it isn't working, do you have the database in a trusted location or the enable code button clicked when opening the database?
 
Oh, and just a note - it really is kind of a waste to do this type of thing because most people have the clock in the lower right-hand part of their screen in the system tray and making a clock like this uses a bit of CPU power which could possibly be set to better usage. But it is your choice.
 
If you just want to see the time portion (sorry I didn't think of this earlier) you can use:
Code:
 Me.YourLabelControl.Caption = Format(Now, "hh:nn:ss AM/PM")

or if you want 24 hour time:

Code:
 Me.YourLabelControl.Caption = Format(Now, "HH:nn:ss")
 
most people have the clock in the lower right-hand part of their screen in the system tray
While this is true, Bob, the number of people who use a computer at work, for hours each and every day, yet don't know that the clock is down there, continually amazes me! And then there are a lot of developers who display their form in 'full-screen' style, which covers up the tray.

I usually include the line

Me.YourLabelControl.Caption = Now

in the Form_Load event as well, because even a simple form takes long enough to load and fire the Timer event that there is a noticeable lag before the time appears.

I took a class in C++ a number of years ago, taught by a 30 years programming veteran, and included a real-time clock in an assignment. The instructor asked my permission (they were very much into the 'intellectual property' thing) to use the bit of code in his apps at his day job! Reason? He'd had three requests from end users for this feature that same week! :D
 
thank you for your help im sure i was doing it the way you have suggested but to no luck i will try again later and see what happens. as i tried it in access 2007 and it works fine.
 
maybe you need to add

DOEVENTS

after you refresh the time caption, to let access show it on screen.

if there are no other pending screen updates, it might not do it yet, if you see what I mean.
 
its ok this was working i had done everything right but the security settings in access where blocking something i think.
 

Users who are viewing this thread

Back
Top Bottom