Problem with VBScript to open a database

I

Irina

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")


WScript.sleep(3000)

MsgBox("close connection")

objConnection.Close
WScript.Quit
 
A

Albert D. Kallal

In your actual sample, I don't see anywhere where you're actually launching
MS access.

I am going to suggest that you move your code to a standard module and place
a subroutine in that module in which your code runs and does your series of
processes that you wanted to accomplish. In your example, you're using the
ado library and jet, but not actually launching MS access.

if you try to run a macro, or some DBA code in a standard code module inside
of MS access, then I suggest the following approach.

you can then run a script and execute that subroutine in a standard code
module as follows:

dim accessApp
set accessApp = createObject("Access.Application")
accessApp.OpenCurrentDataBase("C:\some path name\someMdb.mdb")

accessApp.Run "TimeUpDate"
accessApp.Quit
set accessApp = nothing

The above script will launch ms-access, and then run a sub called TimeUpDate
in a standard code module.

what your code does in the standard sub (called TimeUpdate in above) is up
to you. You can print reports, or do whatever you want.

I explain more how to set dispatch file not following article of mine

http://www.members.shaw.ca/AlbertKallal//BatchJobs/Index.html
 

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