how can i open with vba on microsoft access a database that is protected with a password

Posted on 2014-03-10
Last Modified: 2014-03-10

i have this code to open a non-protected database
Dim accapp As Access.Application
Set accapp = New Access.Application
accapp.OpenCurrentDatabase d("c:\database\mydatabase.mdb")
accapp.Visible = True

Open in new window

what i have to add to this code to open a database that protected with a password?

Question by:bill201
LVL 81

Accepted Solution

zorvek (Kevin Jones) earned 125 total points
ID: 39918203
Some sample code illustrating how to do this:

   Set MyDatabase = New ADODB.Connection
   MyDatabase.CursorLocation = adUseClient
   MyDatabase.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='C:\full\path\to\database.mdb'; User Id=admin; Password=;"

For more information about Open syntax:

Additional help constructing connection strings can be found at:


Assisted Solution

c1nmo earned 125 total points
ID: 39918206
accapp.OpenDatabase("c:\database\mydatabase.mdb"), False, False, ";PWD=mypassword")
LVL 58

Assisted Solution

Gary earned 125 total points
ID: 39918224
Another option, authenticating yourself first then carrying on with your code as normal.
LVL 61

Assisted Solution

mbizup earned 125 total points
ID: 39918226
With the OpenCurrentDatabase command:

Dim accapp As Access.Application
dim strPwd as string

strPwd = "MyPassword123"
Set accapp = New Access.Application
accapp.OpenCurrentDatabase ("c:\database\mydatabase.mdb",, strPwd)
accapp.Visible = True

Open in new window


Author Closing Comment

ID: 39918290
thanks a lot for  your help.

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question