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

real-time Clock

Status
Not open for further replies.

rasticle

Programmer
Sep 25, 2006
42
US
Do any of you know how to display a live moving clock on an Access form? I know how to do the time stamp, but I just thought it would be cool to add in the "live" clock. I was just looking for an example or help in the right direction. Thanks!
 
Have a look at the Timer event procedure of the Form object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Here's a thing I use, based on the same thing PHV was talking about. You'll need a textbox called txtOmega (yeah, I'm a watch fanatic) and you'll maybe want to add some cosmetics to it, like a frame around it. If you'd also like to show the date, add a textbox called txtDayRunner.

Code:
Private Sub Form_Open(Cancel As Integer)
'Displays while waiting for timer to crank up    
     Me.txtOmega = Time 
End Sub

Private Sub Form_Timer()
    Me.txtOmega = Time 'Display time
    Me.txtDayRunner = Date 'Display date
End Sub

And before some says something about Windows already having a clock displayed in the taskbar (and somebody usually does) I run all my apps "full screen mode" as it were, where the Windows clock isn't visible.

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
I usually display mine in the Form's Caption
Code:
Private Sub Form_Timer()
    Me.Caption = "Form Name" & Space(40) & _
    Format(Now(), "dddd, mmmm d, yyyy h:nn:ss AMPM")
End Sub
 
Thank you, but to keep it so it keep counting the time in the live display is there anyway to do that? More specifically when the clock is displayed it shows moving time as opposed to the live time, but at a stand still in the display? Like, I would think I would need to put the code into some sort of a while loop so it keep changing. I hope this makes sense. lol. I am having a hard time coming up with a way to describe this!

Thanks!
 
Putting it in the Private Sub Form_Timer() like both Golom's and my example shows "keeps it changing" with needing a loop.

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
You should also set the form's timer interval to something like
Code:
Me.TimerInterval = 300
Probably in the Form_Load event. You need the timer to fire about 3 times a second to get smooth operation of your clock display. If you set it to longer values then the clock can appear to skip seconds.

If your finest resolution is going to be 1 minute (i.e. you're not displaying seconds) then
Code:
Me.TimerInterval = 1000
is probably fine.
 
Actually Me.TimerInterval = 1000 works better than 300 for displaying seconds, at least it does on my system. Doesn't seem like it would, but setting it to anything less than 1000 results in the display "jerking" and even appearing to cut the count between some seconds short. I always assumed it was just another Access quirk!

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
I haven't had a chance to try it yet. I have been staying at the girlfriends and she doesn't have access on her computer. I should probably envy her for not having it. lol. Thanks for the responses though! I'll let you know if I can finally get the thing to work.
 
This solution from DEv at

Database Solutions for Microsoft Access : Create a working clock on your forms

Looking for that extra special effect to give your Microsoft Access database project a professional flair...Thought about adding a working clock to your Access forms?

To put a simple text clock on a form, create a Label called lblClock on the form, set the form's TimerInterval to 1000, and the following code behind the Timer Event.

You can also create two command buttons called cmdClockStart and cmdClockEnd and attach respective code to each to have the clock run on demand.

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

Private Sub cmdClockStart_Click()
Me.TimerInterval = 1000
End Sub

Private Sub cmdClockEnd_Click()
Me.TimerInterval = 0
End Sub
'***************** Code End ***************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top