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

Having a 'clock' on a form that displays the current time... 1

Status
Not open for further replies.

AccipiterQ

Programmer
May 25, 2005
27
US
Quick question...how would I have it so that the time is displayed on my form, like a clock. I can get the time to display on the form currently as a text label...but the time doesn't update..it just displays whatever time it was when the form was opened. (I used the insert date/time menu option). I see several VBA commands for time, but I'm not sure which one to use...
 
AccipiterQ,
I had the same issue a while back. Here is the answer:

On the form in question, select properties and set Timer Interval to 1000.

Next, right beneath this property, there is another property called "On Timer". Click in the empty field, select the "...", and select "Code Builder". Now, enter this:

Private Sub Form_Timer()
Me.YourTextBoxName.Value = Format(Now, "dddd, DD HH:NN:SS MMMm yyYY")
End Sub

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

Private Sub cmdClockEnd_Click()
Me.TimerInterval = 0
End Sub

Now go back to your form and check it out in "Form View".

You can mess around with the date/time format all you want.

 
k, just one error....when I put all that in, then go to form view....about a second or two in I get an error, and it highlights the line 'Me.Clockbox.value = Format.....'
(I called the text box 'Clockbox'). It tells me 'you can't assign a value to this object


Private Sub Form_Timer()
Me.ClockBox.Value = Format(Now, "dddd, DD HH:NN:SS MMMm yyYY")
End Sub

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

Private Sub cmdClockEnd_Click()
Me.TimerInterval = 0
End Sub
 
Ok, I just deleted the first box I had made and tried your code again, now it says 'method or data member not found' and highlights the '.Value' in '.value=format(Now,....'

 
The textbox ("Clockbox") needs to be an unbound field. Sorry - I should have mentioned that.
 
as a text label
Me!ClockBox.Caption = Format(Now, ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
p.s. how do I get AM or PM' to come after the time??
 
Try this for your format in the code:
Me.Clockbox.Value = Format(Now, "dddd, DD hh:mm AMPM MMMM YYYY")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top