ms-accessmacros

Activate MS Access macro with .bat file


I created a macro in Access VBA that sends tasklist emails to all the staff in our division. I would like to schedule this macro to run every Monday.
It seems I need to create a .bat file that runs this macro, then use Task Scheduler to run this batch file every Monday.

The macro is called ScheduleEmails.
enter image description here

I can run it from the VBA window.

The batch file has the following text: "C:\Program Files\Microsoft Office\root\Office16\MSACCESS.EXE" "C:\Users\42253\Documents\RealEstate\RealEstate_ActionList_V6.accdb" /x ScheduleEmails
enter image description here

When I run this .bat file I get the following error:
enter image description here

I added the folder into the trusted list and the database content is enabled.


Solution

  • The parameter /x calls an Access Macro, not a VBA routine.

    You need to create a Macro in Access, name it for example StartScheduleEmails and have a command RunCode. Note that you need to add the parenthesis to the call, else it will not work.

    enter image description here

    This will execute a Function, not a Sub, so you will need to change the type of ScheduleEmails to Public Function ScheduleEmails()