New2Programming
New2Programming

Reputation: 383

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.

Upvotes: 0

Views: 927

Answers (2)

June7
June7

Reputation: 21370

Macros can only call functions, not subs. As @marlan said, can have code in load event of a form set to open by default and the optional arguments not needed. Another alternative is Windows Task Scheduler calls a script file which has code to open db, call VBA procedure, and close db. Here is structure of a VBScript executable (file extension .vbs).

Dim accessApp
set accessApp = CreateObject("Access.Application")
accessApp.OpenCurrentDataBase("your path/filename here")
accessApp.Run "your procedure name here"
accessApp.Quit
set accessApp = nothing 

Upvotes: 0

Deepak Bhise
Deepak Bhise

Reputation: 171

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.

Upvotes: 0

Related Questions