Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
How to use the OpenDatabase method to open password-protected databases in Access 2000
Article ID: 209953 - View products that this article applies to.
This article was previously published under Q209953
Moderate: Requires basic macro, coding, and interoperability skills.
This article applies only to a Microsoft Access database (.mdb).
This article describes how to use the OpenDatabase method to open a Microsoft Access database that has a database password. Note that this is different from opening a database that is secured with the Microsoft Access user-level security feature.
If you want to use the OpenDatabase method to open a password-protected database, specify the database password as part of the Connect argument. The syntax to open a database with the OpenDatabase method is as follows:
Set db = workspace.OpenDatabase(dbname, options, read-only, connect)NOTE: Even though the Options and Read-Only arguments of the OpenDatabase method are documented in Help as being optional arguments, you must provide them when you use the Connect argument. If you use a Connect argument and you do not provide the Options and Read-Only arguments, you receive run-time error 3031:
You receive this error message even if the password that you provided in the Connect argument is correct. If you do not need to use a Connect argument, you can omit the Options and Read-Only arguments.
Not a valid password.
When you use the OpenDatabase method to open a password-protected Access database, the Connect argument of the OpenDatabase method requires the following syntax:
MS Access;pwd=passwordTo use the OpenDatabase method to open the sample database Northwind.mdb (which is protected with a database password of "northwind"), follow these steps:
NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
For more information about the OpenDatabase method, click Microsoft Visual Basic Help on the Help menu, type opendatabase method in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
For more information about database passwords, click Microsoft Access Help on the Help menu, type protect a microsoft access database (.mdb) file with a password or encryption in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.