Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't pen password protected database from module

Status
Not open for further replies.

ecannelora

Programmer
Feb 4, 2005
34
0
0
US
I want to put a password on my database, but when I try to open it from VBA, I don't know the proper syntax for the password argument:

Dim wsp As Workspace
Dim dbs As Database, dbsOther As Database

Set dbs = CurrentDb
Set wsp = DBEngine.Workspaces(0)
Set dbsOther = wsp.OpenDatabase("z:\pdb\PDB_be2.mdb")

I've tried varaiations of this:

Set dbsOther = wsp.OpenDatabase("z:\pdb\PDB_be2.mdb,password: "myPassword")
but I can't get anything to work. Can you help?
 
I found this, and it worked, so never mind.

Option Compare Database
Option Explicit

Sub OpenPasswordProtectedDB()

'Define as Static so the instance of Access
'doesn't close when the procedure ends.
Static acc As Access.Application
Dim db As DAO.Database
Dim strDbName As String
strDbName = "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb"
Set acc = New Access.Application
acc.Visible = True
Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=nwind")
acc.OpenCurrentDatabase strDbName
db.Close
Set db = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top