Opening a pasword-protected database
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!
Re: Opening a pasword-protected database
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.
Re: Opening a pasword-protected database
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?