Consulting

Results 1 to 5 of 5

Thread: Advice on 'OnTime'

  1. #1
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location

    Advice on 'OnTime'

    Hi all

    I have an application that reads data from a webpage which is updated at 03:45 daily. Occasional updates to the webpage are also carried out at other times, I am notified of these by email.

    I have written this code which should update every morning at 4am and, after hitting a button, when I am emailed notification of an update:

    Option Explicit
    
    
    Global AutoRun As Boolean
    
    
    Sub AutoUpdate()
        Application.OnTime ("04:00:00"), "UpdateData"
    End Sub
    
    
    Sub ManualUpdate() 'run by a command button
        AutoRun = False
        UpdateData
    End Sub
    
    
    Sub UpdateData()
        'Code to update here...
        If AutoRun Then AutoUpdate
        AutoRun = True
    End Sub
    I seldom use OnTime so I am seeking advice as to whether this is okay to go with, or if there is a better way to approach this.

    Any pointers would be most welcome

    Thanks in advance
    Semper in excretia sumus; solum profundum variat.

  2. #2

  3. #3
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    That's the first place I went to, you are my 'goto' site for a vba handbook

    My doubts lie in its' simplicity... can it be reliable?
    Semper in excretia sumus; solum profundum variat.

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    dim y
    
    Sub AutoUpdate()
      M_snb
      y=1+ date + 1/6
      Application.OnTime y, "AutoUpdate"
    End Sub
    
    Sub ManualUpdate() 'run by a command button
       M_snb
    End Sub
    
    sub M_snb()
       '  code to update
    end sub

  5. #5
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Thanks. That looks better, I'll give it a whirl
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

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