programmatically check if an access database is password protected

I

Ivan

Please help. How can I programmatically check if an
access database is password protected using VB
 
B

Brendan Reynolds \(MVP\)

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
 
I

Ivan

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)





.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top