PDA

View Full Version : Application.OnTime not getting canceled



lynnnow
08-17-2013, 12:12 AM
I have a piece of code that checks for the system time and shows a countdown timer at a particular hour... I can set up the timer to run at periodic intervals but I can't seem to figure out why the "Schedule:=False" part fails. Please help me understand why it is failing. See code below


Sub ReRunCheckTime()
ReRunTime = Time + TimeSerial(0, 0, 15)
'Debug.Print Time & vbTab & ReRunTime
If Time >= TimeValue("23:57:00") Then

If frmCountDownTimer.Visible = False Then
frmCountDownTimer.Show 0 'This is the form that is shown
Application.OnTime ReRunTime, "ReRunCheckTime", , False 'This is where it fails
End If
End If
Application.OnTime ReRunTime, "ReRunCheckTime"
End Sub



I've looked up the help files and seen examples on various fora for an understanding on this but don't understand why it should bug out. Should the cancel ontime be in a different sub? If so, why?

p45cal
08-17-2013, 11:17 AM
You can't cancel a schedule which isn't there. I'm guessing you might want to move the Application.Ontime line which is just before the End Sub to just after the line beginning ReRunTime = Time..

lynnnow
08-19-2013, 05:06 AM
You can't cancel a schedule which isn't there.

That explained it for me. Thank you p45cal. I checked the immediate window for that explanation and understood it. Thanks again.