Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
How to Schedule the Running of Queries
Sandi Cushion 
      
9 months ago
I have a form with a button which runs six queries consecutively. Is there anyway that I can schedule this to run at a pre-determined time each weekday morning?
The queries are based on 4 tables: Append, Delete, Append, Update, Make Table and Append.
Sami Shamma  @Reply  
             
9 months ago
Hi Sandi, the simple answer is yes.

Is your database running 24 hours a day?
Do you start your database each morning?
Do you have multiple users?

Depending on those answers, two simple ways to do this are:
1) On the load of the main menu, run that procedure.
2) have a timer event again on the main menu that checks for a specific time of the day to run the procedure.

There are other ways to do this, and Richard has a couple of videos on them. Watch the following.
Sami Shamma  @Reply  
             
9 months ago
Sandi Cushion OP  @Reply  
      
9 months ago
Hi Sami, thank you for your prompt reply.
I am currently in the development stage of this database.  It isn’t running 24 hours a day and won’t ever be.  But I need it to gather daily data from other systems even when I am not in the office. So, although I will start the database sometimes, I need it to work when I am not in the office.  It will eventually only have two or three users.
Sami Shamma  @Reply  
             
9 months ago
Timer event is the way to go.
Sami Shamma  @Reply  
             
9 months ago
Use the same techniques in the Blackout Times video above, but instead of shutting down the system, you'll run your procedure.
Sami Shamma  @Reply  
             
9 months ago
And if that procedure needs to have exclusive access to the database, go ahead and log out your additional users before you execute those six queries.
Adam Schwanz  @Reply  
           
9 months ago
You can set up a task in the windows task scheduler to open your database at a certain time, like 8am. So if you're not in the office it will open itself, and won't need to be left on 24/7. Then you can use normal or timer events, whatever works best for your situation.
Raymond Spornhauer  @Reply  
          
9 months ago
Sandi,

I've started using a hidden form in my database's to perform background functions.

I setup an Admin Table with the following Fields:
Shutdown (Yes/No)
ShutdownDT (Date/Time)

Then I have an Admin Form that only I can can use where I can check the Shutdown Checkbox and it will automatically set the ShutdownDT for 1 min later.

Then in my Hidden Form, I have a Timer Code set to run every minute (60000 msec) as follows:

Private Sub Form_Timer()

    If Shutdown = True And Now() > ShutdownDT Then
        Application.Quit
    End If

End Sub

My Hidden Form (in the user database) is opened during Startup with the following:
DoCmd.OpenForm "FormName", acNormal, , , acFormReadOnly, acHidden

This allows me to force everyone out of the database when I need to make changes.

You could do this same thing to run your queries, but your database would need to be open all the time as stated by Sami.  I had one database setup where the Manager would have the database open all the time on their computer, which would code at specific times.
Raymond Spornhauer  @Reply  
          
9 months ago
Sandi

I also wanted to add that your timer events don't have to run every query every time.

Rick has a video about Variable Scope, https://www.youtube.com/watch?v=bBQH8nWFtzw

What you can do is create a Form Level Variable (added before any of your subroutines, below Option Compare Database)

Dim QueryEventNumber as Integer

On the Hidden Form Load Event, set QueryEventNumber = 1


Now in your Form Timer Event you can put the following:

Private Sub Form_Timer()

'Put the stuff you want to run every time here
Do Stuff

'Now you can put queries you want to run only every so often based on the QueryEventNumber

If QueryEventNumber = 1 Then

     Do the things you want on the first Timer Event

End If

If QueryEventNumber = 2 Then

     Do the things you want on the first Timer Event

End If

'Advance to the next number, or reset back to 1 so it will start over on the next Timer Event
If QueryEventNumber = XX 'whatever you want the max number to be
     QueryEventNumber = 1
Else
     QueryEventNumber = QueryEventNumber + 1
End If

Keep in mind that whatever Query or Function you put in the QueryEventNumber Code will only run as many times as there are options unless you include that query in more than one QueryEventNumber.

You don't have to use a QueryEventNumber... you could do the same thing using a Date or Time, then compare Now() to the Date/Time you want the events to run.

Hope this helps.

-Raymond
Raymond Spornhauer  @Reply  
          
9 months ago
Don't put this code in every database.... have one database that runs this code... or you will have multiple databases running this code one after another.  This can cause issues with Forms or Reports having bad data if they are open in the middle of a query run from any other computer.

-Raymond
Sandi Cushion OP  @Reply  
      
9 months ago
Thank you everyone for your help and support in this matter - it is such a great feeling being part of this group!!
Kevin Robertson  @Reply  
           
9 months ago
Sandi This community is the best you will anywhere (online and offline) :)

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 2:13:27 PM. PLT: 1s