Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / May 2008

Tip: Looking for answers? Try searching our database.

VBScript question - connect and open an Access DB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Irina - 20 May 2008 21:13 GMT
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
Dirk Goldgar - 21 May 2008 01:57 GMT
>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
[quoted text clipped - 33 lines]
>
> --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

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Irina - 21 May 2008 15:16 GMT
Thanks a lot Dirk, I will give that a try.
Appreciate your response

> >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
[quoted text clipped - 50 lines]
>
>     appAccess.Quit
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.