-
Hello all, I am having a small problem in which I hope that
someone can help me with. I have a Access database that is
password protected and I need to open this database with
the following:
Dim oAccess As Access.Application
Set oAccess = CreateObject("Access.Application.8")
oAccess.Visible = False
oAccess.OpenCurrentDatabase "C:\db1.mdb"
oAccess.Quit acQuitSaveAll
Set oAccess = Nothing
Every time that I try to open the db1.mdb the enter
password screen comes up. How do I make is so that the
enter password screen does not come up?
All and any help is appreciated.
Thank you.
-
This is from MSDN Article Q147816
Code:
'----------------------------------------------------------------------
'DECLARATIONS
'----------------------------------------------------------------------
Option Explicit
Dim objAccess as Object
'----------------------------------------------------------------------
'This procedure sets a module-level variable, objAccess, to refer to
'an instance of Microsoft Access. The code first tries to use GetObject
'to refer to an instance that might already be open. If an instance is
'not already open, the Shell() function opens a new instance and
'specifies the user and password, based on the arguments passed to the
'procedure.
'
'Calling example: OpenSecured varUser:="Admin", varPw:=""
'----------------------------------------------------------------------
Sub OpenSecured(Optional varUser As Variant, Optional varPw As Variant)
Dim cmd As String
On Error Resume Next
Set objAccess = GetObject(, "Access.Application")
If Err <> 0 Then 'no instance of Access is open
If IsMissing(varUser) Then varUser = "Admin"
cmd = "C:\Program Files\Microsoft Office\Office\MSAccess.exe"
cmd = cmd & " /nostartup /user " & varUser
If Not IsMissing(varPw) Then cmd = cmd & " /pwd " & varPw
Shell pathname:=cmd, windowstyle:=6
Do 'Wait for shelled process to finish.
Err = 0
Set objAccess = GetObject(, "Access.Application")
Loop While Err <> 0
End If
End Sub