Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command line options

Status
Not open for further replies.

rgbanse

MIS
Jun 4, 2001
211
US
I'm running a mass update of all of our databases using the following -
Call Shell("""C:\Program Files\Microsoft Office\Office11\msaccess.exe"" """ & DatabaseName & """ /x """ & MacroName & """ ", 1)

works fine except for those databases with an autoexec macro or a startup form. is there an option that will bypass both and execute my macro only ?
thx
RGB
 
The short answer is no especially if the database developer has disabled the shift key (which would bypass the AutoExec macro or stop the startup form loading). However you could open the database, run the macro and close it like this.

Public Function RunExternalMacro(ByVal Application As String, ByVal Database As String, ByVal Workgroup As String, ByVal UserName As String, ByVal Password As String, ByVal MacroName As String)
'----------------------
'|Get file references.|
'----------------------
On Error GoTo Err_RunExternalMacro
Dim objAccess As Object
Dim strCommandLine As String

'Use Shell to open File or activates window if File already loaded.
strCommandLine = """" & Application & """"
strCommandLine = strCommandLine & " """ & Database & """"
strCommandLine = strCommandLine & " /wrkgrp """ & Workgroup & """"
strCommandLine = strCommandLine & " /user """ & UserName & """"
strCommandLine = strCommandLine & " /pwd """ & Password & """"
Shell strCommandLine, vbMaximizedFocus

'Wait for shelled process to finish.
Do
Err = 0
Set objAccess = GetObject(strDatabase)
Loop While Err <> 0

objAccess.Docmd.RunMacro MacroName
objAccess.Quit

Exit_RunExternalMacro:
Exit Function

Err_RunExternalMacro:
MsgBox "RunExternalMacro Error: " & Err.Number & ": " & Err.Description
Resume Exit_RunExternalMacro
End Function

This works in VBA but you should be able to adapt it to VBScript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top