Determining programmatically if an Access DB is password protected?

6

'69 Camaro

Hi, Mike.
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.
 
M

mike.michelle

Is there a way programmatically to determine if an Access database is
password protected, so that the login/password dialog isn't shown?

I'm writing an application that scans Office documents, and I want it
to skip Access databases that are password protected. Unfortunately,
everything I've tried so far always brings up the dialog.


Any help is much appreciated!


Thanks
Mike
 
J

Joan Wild

I don't believe so. The login/password dialog is determined by the mdw, not
the mdb.
 
M

mike.michelle

Hi Gunny,

Thanks for the suggestion - I had inherited this from another
developer, who was using a third-party DLL to open the Access docs.

Using your suggestion I simply used the OleDb classes (.Net) to try to
open the database, and if password protected, it throws an exception.

Thanks again,
Mike
 

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