• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How can I display a dynamic Clock in my Userform?

In my userform there is a TextBox called "CM_00". I would like this textbox to display the clock in real-time. Is there a code that could help me to get that?
 

Attachments

  • Sebastian Data Entry (guests V2).xlsb
    112.7 KB · Views: 18
.
Call the StartTimer in the Userform_Initialize event :

Code:
Option Explicit

Dim T

Sub StartTimer()
    T = Now + TimeValue("00:00:01")
    Application.OnTime T, "Update"
End Sub

Sub Update()
    UserForm.T_01.Value = Format(Now, "hh:mm:ss")
    Call StartTimer
End Sub
 
It works amazing. But I can notice that the StartTimer is running in the back. How can I make it stop once the userform is closed. I need the StartTime to run once the userform is open but it to stops once the userform is closed. Can it be possible?
 
It seems to work, but when you close the userform, you can see the macro of the StartTimer still running in the back, if you put the mouse on aby cell, and pay attention to the pointer, you can see it bounces(like counting the clock beats. So I must go to Macros, search for the Stoptimer and manually make it stop. I saw the code you set(which is incredibly amazing) but it can´t make the macro to stop completely, Is it normal? or that is the only way it should behave!
Thank you so much in advance.
 

Attachments

  • Capture.JPG
    Capture.JPG
    102.9 KB · Views: 15
  • Capture2.JPG
    Capture2.JPG
    202.6 KB · Views: 14
This is late but to stop the timer use this macro :

Code:
Sub StopTimer()
On Error Resume Next
    Application.OnTime T, Procedure:="Update", Schedule:=False
End Sub
 
And what if instead the clock to display only "01:38:25", Can it display "01/09/2021 01:38:02 AM", always with the clock running? Can this format be applied to TextBox called "CM_00"?
Once again...Thank you in advance!
 

Attachments

  • Sebastian Data Entry (clock) (1).xlsb
    113.4 KB · Views: 19
Back
Top