Click to See Complete Forum and Search --> : Opening a pasword-protected database


daneb
August 8th, 2000, 09:46 PM
Good day!

I have an Access 97 database which I password-protected. How can I open it in my VB code? I have below my code.

Dim db as Database
Dim dbPswd as string

On Error GoTo ShowErr

dbPswd = "myPswd" ' sample only
Set db = OpenDatabase(App.Path & "\dbf\myDB.mdb", , , ";pwd=" & dbPswd)
.......
.......

ShowErr:
Msgbox Err.Number ": " & Err.Description

I set my password in Access to be "myPswd". When I run my code, as soon as I reach the OpenDatabase statement, I get Error No. 3031 "Not a valid password". What's wrong with my code? If the database is successfully opened with the password, will the database be opened exclusively? Thanks in advance!

Erwin
August 9th, 2000, 01:05 AM
Hi !

You have to set parameter FALSE for Options and ReadOnly. Try like that.

Dim db as Database
Dim dbPswd as string

On Error GoTo ShowErr

dbPswd = "myPswd" ' sample only
Set db = OpenDatabase(App.Path & "\dbf\myDB.mdb", FALSE , FALSE , ";pwd=" & dbPswd)
.......
.......

ShowErr:
Msgbox Err.Number ": " & Err.Description


Let me know if it works.

daneb
August 9th, 2000, 02:59 AM
Thanks for the reply. Your suggestion worked! If I replace the second False parameter w/ True, does this mean that the database is exclusively opened until a db.Close statement is reached? What if it is one of the tables that I want to exclusively open?