Search code examples
ms-accesstaskscheduler

Access 2013 Module in Windows Task Scheduler


I have tried using Windows Task Scheduler to run my Access Database module although I can't figure out how to create the macro for this as I believe this is the only way to do this. The details I have are Program/script:"C:\Program Files\Microsoft Office\Office15\MSACCESS.EXE"Add Arguments(optional):"C:\deskop\Reports.accdb" /x AutoExec I have created a macro on my access database called AutoExec but I don't know how to call my module which is called Main.

My Module contains 5 different public functions and a Sub which I changed to Function. I have now added all 5 functions as RunCode and function name to the macro is this correct? it seems to be running the macro now.


Solution

  • you can do this in below steps

    Step 1 : Create a macro (AutoExec in your case ) in database and call the function (main in your case).

    Step 2: Create a batch file, now in batch file you will write a code to open your database and call the macro that you want to execute (AutoExec)

    e.g.

    if exist "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" ("C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" C:\AccessDatabase\MyDatabase.accdb /x:AutoExec)
    

    When this batch file is exacuted, access database will be opened and AutoExec Macro from that database will run which inturn call your function and then complete the task that you want to do.

    Step 3: in this step, create a scheduled task in Windows task scheduler. Create a new action as start a program and provide the above Step 2 created batch file path in Program/Script.

    enter image description here

    As per schedule you setup this will run the batch fle and hence the later access and macro and your function....

    hope this helps.