Link to home
Start Free TrialLog in
Avatar of gcassel
gcassel

asked on

Run query everyday at 2PM

I am writing a VB6.0 project over an Access 2000 backend.  My users want the program to automatically query the database everyday at 2PM.  What is the best way to code this?
Thank you.
Avatar of AzraSound
AzraSound
Flag of United States of America image

programmatically you could do it with a timer...which doesnt have to have a short interval since the time specified is not exact (minutes or seconds wise)

Private Sub Timer1_Timer()
    If Hour(Now) = 14 Then
        MsgBox "run the query - its 2PM"
        Timer1.Enabled = False
    End If
End Sub

you could have a very large interval and still be ok


however i imagine there must be some sort of scheduling tool built into either the operating system you are using or even Access 2000 itself.  you may look into that as that would be the most reliable solution.
Avatar of GivenRandy
GivenRandy

The timer will only go to ~65000 milliseconds, so the most you can make it is about 1 minute intervals.  SO, Azrasound is close....

Has to have

If ((Hour(Now) = 14) And (Minute(Now) = 0)) Then

With the timer interval at 60000.
With mine, it should not abort the timer.  With Azrasound's, you have to restart the app every day.

Either way, you should probably run a scheduled task instead.  Are you using WinNT or Win2000?
no it doesnt matter...the point i was making was that he doesnt have to trigger a query at, say, 2:05:23 PM
its just 2PM...not too exact and thus the timer interval need not be small.  my code would trigger whether the interval was 1 or 65000, either way, it would trigger at about 2 PM. how close he wants to get it to 2 PM is how he would manage the interval.
well i assumed this program wasnt run 24 hours a day, i assumed it was started at the beginning of the day and shut down at night.
ASKER CERTIFIED SOLUTION
Avatar of philchang
philchang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The easiest way to do that is using Sleep API.

Giving Sleep(Milliseconds) will not consume your memory also.

manchula: how can sleep make it fire an event on 2pm in the day?

qcassel: I think you should use a Timer, set it's interval to 60000 (1 minute) then update the time every minute. If the time is 2pm then do somethin: eg:

Timer1.Interval = 60000

Timer1sub:
If Format(Time, "HH") = "2" Then
' do what ever:
MsgBox "It's 2pm!!"
End If


you may need to change the Format thing around to make it work with your system.

thanks
manchula: how can sleep make it fire an event on 2pm in the day?

qcassel: I think you should use a Timer, set it's interval to 60000 (1 minute) then update the time every minute. If the time is 2pm then do somethin: eg:

Timer1.Interval = 60000

Timer1sub:
If Format(Time, "HH") = "2" Then
' do what ever:
MsgBox "It's 2pm!!"
End If


you may need to change the Format thing around to make it work with your system.

thanks
manchula: sleep is blocking and will basically freeze your program for x number of milliseconds.  (i.e. it will not be able to be closed except by end task).

You would be better off with a timer if you wanted to keep a program running, or a scheduler if you did not.

If you want to use a timer, try building a code-only timer.  That way, you can set larger intervals.  You can find one at http://www.inquiry.com