Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Run query everyday at 2PM

Posted on 2000-05-05
10
Medium Priority
?
421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

719 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