Solved

Run query everyday at 2PM

Posted on 2000-05-05
10
403 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:gcassel
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2783370
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.
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2783377
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.
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2783382
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?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2783383
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.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2783388
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.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Accepted Solution

by:
philchang earned 200 total points
ID: 2783559
I am assuming that since it's a scheduled query that this is an Insert, Delete, or Update query.  If it's a Select query, I'm guessing that you want to do something other than display it on the screen (such as print it out).

The easy way would be to build a program with no form and then to schedule the task using the Scheduler that comes with Win2000 or with Plus98.

Have a Sub Main() that executes your query and then terminate with an End statement.  Otherwise, an OS bug (feature?) sometimes leaves the process running.

If your query is long, make sure to set the connection timeout property of the connection object

Phil
0
 
LVL 1

Expert Comment

by:manchula
ID: 2783614
The easiest way to do that is using Sleep API.

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

0
 

Expert Comment

by:LeXien
ID: 2783847
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
0
 

Expert Comment

by:LeXien
ID: 2783848
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
0
 
LVL 1

Expert Comment

by:philchang
ID: 2786129
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now