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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Running Time on Access Form 1

Status
Not open for further replies.

Pulse99

MIS
Oct 30, 2003
4
US
Hi...I'm new at this (both the forum and Access Programming). Can anyone help with how to get continually updated display of the current time on an Access form in Access 2002. I've tried using the Now() and Time() function in the DefaultValue property, but the time doesn't continue update after the the form initially opens.
 
Use a Form_Timer event to update the value in a textbox, label or status bar at the bottom.

If you set the timer event to run every second or minute, for example, this will do the work, but remember that the longer or more complex the event code, the longer it will take to execute, which will affect the speed of your application. I would do serious testing with different interval values to find out what is best in your case.

John
 
To add to what jrbarnett has said, be aware that the Timer will not always fire at the exact interval for a variety of reasons. You also must yield to the processor (DoEvents) to allow the Timer event to be processed.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The following 7 steps were provided in an example database by Klaus Oberdalhoff.

1. In Form Design mode, place a label on your form where you want the clock displayed. You will need to put a temporary character in the label box to keep it open

2. Select the label box and set the Name property to lblClock.

3. Set the other properties for the control as well. For example, you might want to have larger font, bold font, center justified etc.

4. Select the form to set the form properties [If you have the ruler displayed, press your left mouse button in the small white box between the zeros in the upper left hand corner, this will select the form].

5. The last property listed is the “Timer Interval”. Set it to 1000.

6. In the box above, the “On Timer” Property, press the ellipses “...” button and then select “Code Builder”

7. Insert this one simple line: “lblClock.Caption = Now” This will display the date and time. If you would rather just show the time then enter: “lblClock.Caption = Time”

I personally prefer to put the clock in the form header or footer section. However, it makes no difference where you place it.

Sean.
 
Thanks to both replies....I've tried using the timer event and it works very well. I set the timer interval to update every second (1000 ms). Thanks also for the insight into the possibility of the timer event not firing. As it happens, it's not critical that it goes off every time. I just need it to go off enough that when users do look at the time they see something reasonably clost to the system time. Thanks a lot, guys! Ray
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top