VBScript question - connect and open an Access DB

I

Irina

I have a question that you may or may not be able to help me with.
I have a database with Autoexec Macro in it (which would run when a user
opens the DB) I dont want to open that particular DB manually. So I have a
script that would open the DB and the macro will run (macro just creates a
copy of a certain table with a date appended to the name of the table for
backup purposes). I can not get the script to work. It is a VBScript, and it
says that it is running, however the macro is not being run because there is
no resulting table from the macro.
Here is the code in case you can help with this


Dim objConnection
Dim objRecordSet

Set wshshell = WScript.CreateObject("WScript.Shell")
Set objConnection = CreateObject("ADODB.Connection")

Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source
=F:\Litigation\Immigration\Immigration Database\Immigration Reports_BE.mdb;"


MsgBox("Connected to Immigration DB")

'appAccess.DoCmd.RunMacro "AutoExec"
MsgBox("Macro")

WScript.sleep(3000)

MsgBox("close connection")

objConnection.Close
WScript.Quit

--I appreciate your help
 
D

Dirk Goldgar

Irina said:
I have a question that you may or may not be able to help me with.
I have a database with Autoexec Macro in it (which would run when a user
opens the DB) I dont want to open that particular DB manually. So I have a
script that would open the DB and the macro will run (macro just creates a
copy of a certain table with a date appended to the name of the table for
backup purposes). I can not get the script to work. It is a VBScript, and
it
says that it is running, however the macro is not being run because there
is
no resulting table from the macro.
Here is the code in case you can help with this


Dim objConnection
Dim objRecordSet

Set wshshell = WScript.CreateObject("WScript.Shell")
Set objConnection = CreateObject("ADODB.Connection")

Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source
=F:\Litigation\Immigration\Immigration Database\Immigration
Reports_BE.mdb;"


MsgBox("Connected to Immigration DB")

'appAccess.DoCmd.RunMacro "AutoExec"
MsgBox("Macro")

WScript.sleep(3000)

MsgBox("close connection")

objConnection.Close
WScript.Quit

--I appreciate your help


Opening a connection to the database is not the same as opening the database
in access. The autoexec macro will only run if you open the database in
Access. For your script's purposes, I believe you can do that by creating
and automating an Access Application object. For example,

Dim appAccess

Set appAccess = CreateObject("Access.Application")

appAccess.OpenCurrentDatabase _
"F:\Litigation\Immigration\Immigration Database\Immigration
Reports_BE.mdb"

WScript.Sleep(3000)

appAccess.Quit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top