Connecting to a password protected mdb file

I

IgorM

Hi
I have an access mdb file with an Admin user and a password set for the
user. So basically when I try to open the mdb file a userform pops up
asking to provide user name and password for the database. If I don't
give a correct password or user name I cannot access the file. I tried
to use this in Excel VBA (see code below). It takes a user name and
password from a userform, connects to the database and retrieves each
table name. Unfortunately, if I provide a password (ie the same password
when opening the file through Windows Explorer) I cannot access the
file. I get an error: "Cannot start your application. The workgroup
information file is missing or opened exclusively by another user."

But if I leave the password blank it connects to the database and
retrieves table names. Why is that?

Private Sub cmdLogIn_Click()
Dim objCatalog As ADOX.Catalog
Dim objTable As ADOX.Table

Set objCatalog = New ADOX.Catalog

' Check if the database file path is set. If Not Len(gsDatabaseFilePath)
0 Then MsgBox gsMSG_DATABASE_FILE_NOT_SPECIFIED, vbInformation +
vbOKOnly, gsAPP_NAME
Exit Sub
End If

On Error GoTo ErrorHandler ' Check if user name is not a null string. If
Len(txtUserName.Text) > 1 Then gsDatabaseConnectionString =
"Provider=Microsoft.ACE.OLEDB.12.0; " & _ "Data Source=" &
gsDatabaseFilePath & "; " & _ "User ID=" & txtUserName.Text & "; " & _
"Password=" & txtPassword.Text objCatalog.ActiveConnection =
gsDatabaseConnectionString

For Each objTable In objCatalog.Tables MsgBox objTable.Name
Next objTable
Exit Sub
Else MsgBox gsMSG_WRONG_CREDENTIALS, vbInformation + vbOKOnly,
gsAPP_NAME Exit Sub
End If

ErrorHandler: MsgBox gsMSG_WRONG_CREDENTIALS & " " & Err.Description,
vbInformation + vbOKOnly, gsAPP_NAME

End Sub
 

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