User Form: Cannot Update Text Box
Greetings:
I am writing a user form that includes an Event Clock which I am
trying to implement as a Text Box that gets updated every second
with the current time.
When the form is open, the following code initializes the clock:
Public Sub UserForm_Initialize()
Application.OnTime Now + TimeValue("00:00:01"), "Display_Time"
End Sub
Now the Display_Time subroutine is defined and implemented in
code module of the User Form. When I step into this initialize sub-
routine, I get the following error:
The macro EventTimer.xls!Display_Time cannot be found.
I tried placing Display_Time subroutine in a separate code module,
but then got a run-time error complaning:
Run-time Error '424'
Object Required
Here's the Display_Time subroutine:
Public Sub Display_Time()
Dim CurTime, CurHour, CurMinute, CurSecond As Integer
CurTime = Now() Mod 1
CurHour = Int(CurTime * 24)
CurTime = (CurTime * 24) Mod 1
CurMinute = Int(CurTime * 60)
CurTime = (CurTime * 60) Mod 1
CurSecond = Int(CurTime * 60)
EventClock.Text = Format$(CurHour, "00") & ":" & _
Format$(CurMinute, "00") & ":" & Format$(CurSecond, "00")
Application.OnTime Now() + TimeValue("00:00:01"), "Display_Time"
End Sub
The run-time error appears to occur because the EventClock object
is undefined in the separate code module I created.
So my question is, where can I define a subroutine to be executed
every second that can succesfully update the EventClock object on
my User Form? Or on the other hand, how can I somehow make the
EventClock object known to my Display_Time subroutine so that I
don't get a run-time error when I attempt to update this object?
Respectfully,
Charles Ritz
|