Solved

Run query everyday at 2PM

Posted on 2000-05-05
10
405 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 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

14 Experts available now in Live!

Get 1:1 Help Now