[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3113
  • Last Modified:

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

hi


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?

thanks
0
bill201
Asked:
bill201
4 Solutions
 
zorvek (Kevin Jones)ConsultantCommented:
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:

    http://msdn.microsoft.com/en-us/library/ms808201.aspx

Additional help constructing connection strings can be found at:

    http://www.connectionstrings.com/

Kevin
0
 
c1nmoCommented:
accapp.OpenDatabase("c:\database\mydatabase.mdb"), False, False, ";PWD=mypassword")
0
 
GaryCommented:
Another option, authenticating yourself first then carrying on with your code as normal.

http://support.microsoft.com/kb/235422
0
 
mbizupCommented:
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

0
 
bill201Author Commented:
thanks a lot for  your help.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now