Solved

Run query everyday at 2PM

Posted on 2000-05-05
10
411 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 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