Link to home
Start Free TrialLog in
Avatar of M A
M AFlag for United States of America

asked on

Run code at 12 AM everyday in MS Access

Set timer to run at 12 AM everyday in access how to do that. You can see the code and details in the below thread.
i want to run the macro everyday 12AM. I search for it and could not find how to run on specific time.

https://www.experts-exchange.com/questions/29115749/Loop-through-query-and-send-email-everyday-at-12AM.html
Avatar of ste5an
ste5an
Flag of Germany image

Built a separate front-end, which sends the mails started by using the AutoExec macro. Create a scheduled task, which starts that front-end at 12am.
SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M A

ASKER

Thanks to both for your comments.
This a code in Form Timer
User generated image
You missed Mlanda's and my point:

Get rid of the timer. The scheduling is done by invoking the send method via the scheduled task and the AutoExec macro or the VBScript.
i.e:
The Access db is closed.
The Windows Task Scheduler runs the VBScript .vbs file.
The Access db opens...
The autoexec runs....
The VBA process runs....
The VBA code can close the Access file, or do whatever you want it to when it's finished.
Wait for the scheduler to run again at 12:00 AM

Simple....
Avatar of M A

ASKER

I created a script and I get this error. It is not opened.
 User generated image
When using the AutoExec approch, we don't need the VBScript.
I prefer using the timer approach, sometimes the Task Scheduler doesn't work. I have a client that is a summer camp and I set up the timer to play the bugle (Taps) every night at 9PM. The output jack on the computer hooked into the PA system.
The Timer sitting on a form will ONLY fire when the Access Database and that Form are open. The Task Scheduler approach will work so long as the Windows machine is powered up and running and will give you a history of previous invocations and whether they succeeded or failed - which makes for a more robust solution in my view.

Maybe use a hybdrid approach:
- You VBScript can check if the Access lock file exists - if it exists - the DB is open and it must not execute.
- The (Access form based) Timer will then fire instead.

Both approaches would work and combine to give a good solution.
Avatar of M A

ASKER

I ended up with this batch file and scheduled this batch filie to run everyday 12AM.
START "" /MAX "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" "D:\HRM\HRMS.accdb" /x passportnotify30days

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M A

ASKER

START "" /MAX "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" "D:\HRM\HRMS.accdb" /x passportnotify30days

I used this and added docmd.quite as suggested by mbizup.