programmatically check if an access database is password protected

  • Thread starter Thread starter Ivan
  • Start date Start date
I

Ivan

Please help. How can I programmatically check if an
access database is password protected using VB
 
Trap the error that will be raised if you try to open it without the
password?

Public Sub TestPass()

Dim db As DAO.Database
Dim boolOpen As Boolean

On Error GoTo ErrorHandler
Set db = DBEngine.OpenDatabase(path/name here)
boolOpen = True
db.Close
boolOpen = False
Set db = Nothing
MsgBox "No, it's not password protected."

ExitProcedure:
If Not db Is Nothing Then
If boolOpen Then
db.Close
boolOpen = False
End If
Set db = Nothing
End If
Exit Sub

ErrorHandler:
Select Case Err
Case 3031
MsgBox "Yes, it's password protected."
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
Resume ExitProcedure

End Sub
 
Thanks Brendan

-----Original Message-----

Trap the error that will be raised if you try to open it without the
password?

Public Sub TestPass()

Dim db As DAO.Database
Dim boolOpen As Boolean

On Error GoTo ErrorHandler
Set db = DBEngine.OpenDatabase(path/name here)
boolOpen = True
db.Close
boolOpen = False
Set db = Nothing
MsgBox "No, it's not password protected."

ExitProcedure:
If Not db Is Nothing Then
If boolOpen Then
db.Close
boolOpen = False
End If
Set db = Nothing
End If
Exit Sub

ErrorHandler:
Select Case Err
Case 3031
MsgBox "Yes, it's password protected."
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
Resume ExitProcedure

End Sub

--
Brendan Reynolds (MVP)
(e-mail address removed)





.
 
Back
Top