424,279 Members | 1,907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,279 IT Pros & Developers. It's quick & easy.

Running a macro automatically

P: 1
Hello all,

I am trying to make a macro run nightly. I have a task scheduler to open the database, and on the opening form I have put a time interval code set. However, I am unsure what time interval amount I should put. Let's say I put 6000. Upon testing this, it printed the report continuously every 6 seconds.

How can I make it run just once, then stop?

This is the code I used, thanks to a 2007 post on here:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer()
  2. If intCounter > 1 Then
  3.   Me.TimerInterval = 0
  4.   DoCmd.Quit
  5. Else
  6.   DoCmd.RunMacro "mcrTest"
  7. End If
  9. intCounter = intCounter + 1
  10. End Sub
thanks in advance!
Sep 13 '18 #1
Share this Question
Share on Google+
2 Replies

Seth Schrock
Expert 2.5K+
P: 2,919
For other's reference, here is the link to the thread referenced.

I have done this a few times, and I do what was described in post #2
I've never actually done this, and I didn't have the time to test it, but you should be able to run Microsoft Access with the /x macroname Command Line Option as a Daily Scheduled Task if you are using Windows XP. Here is the procedure:
Start Menu
System Tools
Scheduled Tasks
Add a Scdeduled Task
Select Program to Run
Add any necessary Parameters
Select Open the Advance Properties Dialog when finished
Specify the /x macroname Command Line Option on the Command Line
Have your macro call a function that runs your report and then closes the database. You don't need any of the timer form or the If-then-else statement.
Sep 13 '18 #2

Expert Mod 15k+
P: 31,186
You can find some extra info at Invoking a Database From the Command Line.
If you want to run it once only, every time it's opened then include the following code at the end :
Expand|Select|Wrap|Line Numbers
  1. Call Quit(Option:=acQuitSaveNone)
Sep 13 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.