title: Opening an MS-Access database from the command line without running any of the startup vba code?
body: <p>Is there a way to open an MS-Access 2003 database from the command line without running any of the startup vba code or displaying any errors?</p>
  
  <p>I looked at the <a href="http://support.microsoft.com/kb/209207" rel="nofollow">command line arguments for MS Access</a> and there doesn't seem to be one for specifying that you want none of the vba code to execute on startup.  </p>
  
  <p>I'm using the following <a href="http://support.microsoft.com/kb/192919" rel="nofollow">code</a> to open up a database in a separate vba database: </p>
  
  <pre><code>Sub test()
  
  
  Dim accObj As Access.application, Msg As String
  Dim application As String, dbs As String, workgroup As String
  Dim user As String, password As String, cTries As Integer
  Dim x
  
  Dim theDB As Database
  
  ' This is the default location of Access
  application = "C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE"
  
  ' Use the path and name of a secured MDB on your system
  dbs = "C:\ucpdatas\awashic-pc\APLReporting.mdb"
  
  ' This is the default working group
  workgroup = "E:\Tickets\CSN_NotSure\Secured.mdw"
  user = "aleer"
  password = "****"
  
  Debug.Print application &amp; " " &amp; Chr(34) &amp; dbs &amp; Chr(34) &amp; " /nostartup /user " &amp; user &amp; " /pwd " &amp; password &amp; " /wrkgrp " &amp; Chr(34) &amp; workgroup &amp; Chr(34), vbMinimizedFocus
  
  x = Shell(application &amp; " " &amp; Chr(34) &amp; dbs &amp; Chr(34) &amp; " /nostartup /user " &amp; user &amp; " /pwd " &amp; password &amp; " /wrkgrp " &amp; Chr(34) &amp; workgroup &amp; Chr(34), vbMinimizedFocus)
  
  
  On Error GoTo WAITFORACCESS
  Set accObj = GetObject(, "Access.Application")
  
  ' Turn off error handling
  On Error GoTo 0
  
  ' You an now use the accObj reference to automate Access
  Debug.Print "Access is now open."
  
  ' Do Stuff...
  
  accObj.CloseCurrentDatabase
  accObj.Quit
  
  ' Close it out...
  Set accObj = Nothing
  Debug.Print "Closed and complete."
  
  Exit Sub
  
  WAITFORACCESS: ' &lt;--- this line must be left-aligned.
  ' Access isn't registered in the Running Object Table yet, so call
  ' SetFocus to take focus from Access, wait half a second, and try again.
  ' If you try five times and fail, then something has probably gone wrong,
  ' so warn the user and exit.
  
  'SetFocus
  
  If cTries &lt; 5 Then
     cTries = cTries + 1
     Sleep 500 ' wait 1/2 seconds
     Resume
  Else
     Debug.Print "It didn't work"
  End If
  
  End Sub
  </code></pre>
  
  <p>This line... <br/>
  <code>x = Shell(application &amp; " " &amp; Chr(34) &amp; dbs &amp; Chr(34) &amp; " /nostartup /user " &amp; user &amp; " /pwd " &amp; password &amp; " /wrkgrp " &amp; Chr(34) &amp; workgroup &amp; Chr(34), vbMinimizedFocus)
  </code>
  <br/>
  Turns out to be... <br />
  <code>C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE "C:\ucpdatas\awashic-pc\APLReporting.mdb" /nostartup /user aleer /pwd *** /wrkgrp "E:\Tickets\CSN_NotSure\Secured.mdw"  2</code> 
  ... at the command line.</p>
  
  <p>But when the database opens it executes a bunch of vba codes and displays error messages.</p>