How to schedule a call to an MS Access macro?

Dmitri Boulanov picture Dmitri Boulanov · Feb 11, 2013 · Viewed 8.1k times · Source

I'm looking to schedule a call to an MS Access macro. This macro uses a .csv file (that I get daily) to update a SharePoint calendar. Could someone please explain how to schedule a daily call to run this macro (I'm using Access 2003, say EventsCalendar.accdb and macro called Run1) on my Windows 7 machine? I need to automate it to run every morning.

Thanks!

Answer

Yawar picture Yawar · Feb 12, 2013

Write a VBScript script that can run the macro straight from Windows. You can do this by first creating an Access application object in your script and then placing this Access object before all calls in the script which need it. For example,

' RunMyMacro.vbs

set accessApp = CreateObject("Access.Application")

accessApp.OpenCurrentDatabase "C:\db\mydb.accdb"
accessApp.DoCmd.RunMacro "MyMacroName"
accessApp.CloseCurrentDatabase
accessApp.Quit

set accessApp = nothing

This script is now runnable from the Windows shell or from the command line:

C:\db>cscript //B //Nologo  RunMyMacro.vbs

And so you can schedule it as a Windows scheduled task.