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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now