---Update---
As per below.... With a massive thanks to Daniel Pineault I have managed to open a DB and use the /User and /pwd switches to pass a variable automatically!!
Note: I slightly edited it to include the /pwd switch
What I now DON'T know how to do, is run a macro after the DB is opened (from this code)!
Regards
Steve
'*******************************************************************************
'Date: 2008-05-27
'Author: Daniel Pineault / CARDA Consultants Inc.
'
http://www.cardaconsultants.com
'Copyright: You are free to use the following code as you please so long as
' this header remains unaltered.
'Purpose: Launch the specified access database
'Revision: 2008-05-27 Initial Release
'*******************************************************************************
Dim sAcc
Dim sFrontEnd
Dim sSec
Dim sUser
Dim sPW
Dim objShellDb
Dim sComTxt
'Script Configuration Variable
'*******************************************************************************
'Specify the Fullpath and filename of the msaccess executable
sAcc = "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.exe"
'Specify the Fullpath and filename of the database to launch
sFrontEnd = "C:\Directory\MyDBFile.mdb"
'If your database is secured by an mdw file specify it below, otherwise
'leave its value blank
sSec = "C:\Directory\MyMDWFile.mdw"
'If your database is secured by an mdw file and you want to specify the
'username to use specify it below, otherwise leave its value blank
sUser = "UsernameHERE"
'password to use specify it below, otherwise leave its value blank
sPW = "PasswordHERE"
'*******************************************************************************
'*******************************************************************************
'You should not need to edit anything below this point
'*******************************************************************************
'*******************************************************************************
'Launch database
'*******************************************************************************
Set objShellDb = CreateObject("WScript.Shell")
'Build the command to launch the database
sComTxt = chr(34) & sAcc & chr(34) &_
" " & chr(34) & sFrontEnd & chr(34)
if isNull(sSec)=False AND sSec<>"" Then
sComTxt = sComTxt & " /wrkgrp " & chr(34) & sSec & chr(34)
End if
if isNull(sUser)=False AND sUser<>"" Then
sComTxt = sComTxt & " /user " & sUser
End if
if isNull(sPW)=False AND sPW<>"" Then
sComTxt = sComTxt & " /pwd " & sPW
End if
objShellDb.Run sComTxt 'Launch the database