Timed Event

J

John V

I wish to run one web query every, say, three minutes or so, and another web
query daily. I now wish to add additional coding related to the daily query
that extracts info from the query and places it in a table.

Right now, I use Connections Properties to refresh every X minutes for both
queries, but things will get more complicated due to the table coding.

Here is the code I've often seen to control timed events.

Public RunWhen As Double
Public PauseStuff As Boolean
Public Const cRunIntervalSeconds = 120 ' two minutes
Public Const cRunWhat = "GetData3" ' the name of the procedure to run
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat,
Schedule:=True
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat,
Schedule:=False
End Sub

My questions are:
1. Should I continue to use the Connections Properties settings to govern
the refresh rates, or should I programmatically refresh within my GetData3
subroutine?
2. I could treat both queries the same, both refreshing every 3 minutes, but
this seems inefficient. Should I concern myself with this? If so, how do I
refresh one query every three minutes, and the other every 24 hours?
3. How, if at all, can I programmatically pause, then restart all this
refreshing? I have tried a button linked to the StopTimer subroutine, but it
didn't seem to work, and I had no visual clue about the current state (start
vs stop).
4. I've read about and experienced the above code resurrecting itself after
closing the workbook, opening up the closed workbook to run. I assume I need
a workbook BeforeClose routine to call StopTimer. Please advise.

Obviously, I need help. Many thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top