スタートアップ vba コードを実行したり、エラーを表示したりせずに、コマンド ラインから MS-Access 2003 データベースを開く方法はありますか?
MS Accessのコマンド ライン引数を調べましたが、起動時に vba コードを実行しないように指定する引数がないようです。
次のコードを使用して、別の vba データベースでデータベースを開きます。
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 & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & " /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbMinimizedFocus
x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & " /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & 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: ' <--- 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 < 5 Then
cTries = cTries + 1
Sleep 500 ' wait 1/2 seconds
Resume
Else
Debug.Print "It didn't work"
End If
End Sub
この行...
x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & " /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbMinimizedFocus)
結局のところ...
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
... コマンドラインで。
しかし、データベースを開くと、一連の vba コードが実行され、エラー メッセージが表示されます。