1

I'm trying to run a tool created in Access through a VB Script, but it needs to receive 7 variables to run. I don't know how to send data to Access for it to use when running the tool, and all the other posts say to connect directly with the database, but the tool is too complex to do that efficiently.

Here's the code so far:

'initialise variables to hold the parameters passed in
Dim v_VBTOOL
Dim v_Procedure
Dim o_accessApp

'Assign the parameters to the variables
v_VBTOOL = WScript.Arguments(0)
v_Macro =WScript.Arguments(1)

Wscript.echo "The Database to open is " & v_VBTOOL
Wscript.echo "The Macro to run is " & v_Macro


'Create an MSAccess application Object 
'=================================================
Set o_accessApp = createObject("Access.Application")


'Open the required VBTestTool database
'=================================================
o_accessApp.OpenCurrentDataBase(v_VBTOOL)


'Now run the relevant Macro
'=================================================
o_accessApp.DoCmd.RunMacro(v_Macro)

If Err.Number > 0 Then
   ' There was an error.  Inform the user and halt execution
    strMsg = "The following error was encountered while compacting database:"
    strMsg = strMsg & vbCrLf & vbCrLf & Err.Description
    WScript.Echo strMsg

Else
    WScript.Echo "VBTOOL PROCEDURE WAS SUCCESSFUL"
    o_accessApp.Quit
    Set accessApp = nothing
End If

Any help or tips would be appreciated!

4

0 回答 0