6
'69 Camaro
Hi, Mike.
Yes. Use the OpenDatabase( ) method to open the database. If you receive
error # 3033, then a secure workgroup file is protecting the database, and
if you'd have tried to open it by double-clicking on the file name, you
would have been prompted with the user ID and password prompt. If you
receive error # 3031, then a database password is protecting the database,
and if you'd have tried to open it by double-clicking on the file name, you
would have been prompted with the password prompt.
Try the following code:
Public Sub testSecDB()
On Error GoTo ErrHandler
Dim wkSpc As Workspace
Dim db As Database
Dim fOpenedWkSpc As Boolean
Dim fOpenedDB As Boolean
Set wkSpc = DBEngine.Workspaces(0)
fOpenedWkSpc = True
Set db = wkSpc.OpenDatabase("C:\Test\MyDB.mdb", True, False, _
"MS Access;PWD=")
fOpenedDB = True
CleanUp:
If (fOpenedDB) Then
db.Close
fOpenedDB = False
End If
If (fOpenedWkSpc) Then
wkSpc.Close
fOpenedWkSpc = False
End If
Set db = Nothing
Set wkSpc = Nothing
Exit Sub
ErrHandler:
MsgBox "Error in testSecDB( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp
End Sub
HTH.
Gunny
See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
Is there a way programmatically to determine if an Access database is
password protected, so that the login/password dialog isn't shown?
Yes. Use the OpenDatabase( ) method to open the database. If you receive
error # 3033, then a secure workgroup file is protecting the database, and
if you'd have tried to open it by double-clicking on the file name, you
would have been prompted with the user ID and password prompt. If you
receive error # 3031, then a database password is protecting the database,
and if you'd have tried to open it by double-clicking on the file name, you
would have been prompted with the password prompt.
Try the following code:
Public Sub testSecDB()
On Error GoTo ErrHandler
Dim wkSpc As Workspace
Dim db As Database
Dim fOpenedWkSpc As Boolean
Dim fOpenedDB As Boolean
Set wkSpc = DBEngine.Workspaces(0)
fOpenedWkSpc = True
Set db = wkSpc.OpenDatabase("C:\Test\MyDB.mdb", True, False, _
"MS Access;PWD=")
fOpenedDB = True
CleanUp:
If (fOpenedDB) Then
db.Close
fOpenedDB = False
End If
If (fOpenedWkSpc) Then
wkSpc.Close
fOpenedWkSpc = False
End If
Set db = Nothing
Set wkSpc = Nothing
Exit Sub
ErrHandler:
MsgBox "Error in testSecDB( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp
End Sub
HTH.
Gunny
See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.