15

I would like to have a script to:

  1. Open an Access .accdb file
  2. Run a macro within the database
  3. Leave this open

I can very easily do the first two with the following VB script:

dim accessApp
set accessApp = createObject("Access.Application")
accessApp.visible = true
accessApp.OpenCurrentDataBase("C:\path.accdb")
accessApp.Run "myLinker"

But it immediately closes the Access database when the VBS execution finishes. I would like the instance to remain open independent of the script.

I am not forced to use VBScript for this but it definitely seems the easiest to actually invoke the macro to run.

2 Answers 2

23

If you want to leave the application open after the script completes you need to set the UserControl property to true.

dim accessApp
set accessApp = createObject("Access.Application")
accessApp.visible = true

accessApp.UserControl = true

accessApp.OpenCurrentDataBase("C:\path.accdb")
accessApp.Run "myLinker"

The Visible property is technically unnecessary when the UserControl property is true. It will automatically be set.

More information here: http://msdn.microsoft.com/en-us/library/office/ff836033.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Great, thanks. The description on the Application methods page is terribly vague and not useful with respect to its implication - You can use the UserControl property to determine whether the current Microsoft Access application was started by the user or by another application with Automation, formerly called OLE Automation. Read/write Boolean Guess that shouldn't surprise me from MSDN at this point...
2

You could also just use a .bat or .cmd file and put this because MSACCESS has a command line switch for running a macro and unless that macro closes the database it will remain open for user control.

START "" /MAX "PATH\TO\MSACCESS.EXE" "C:\path.accdb" /x myLinker

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.