Consulting

Results 1 to 3 of 3

Thread: Application.OnTime not getting canceled

  1. #1
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location

    Application.OnTime not getting canceled

    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?

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    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..
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    Quote Originally Posted by p45cal View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •