Password cannot be changed through VBA

D

Dkline

Code modified from
http://support.microsoft.com/default.aspx?scid=kb;en-us;235422 as noted in
Eric Butt's reply in the conversation "Importing data from secured database
with a password". In my case I want to export to the database.

What I get is run time error #3621 "Cannot change password on a shared open
database" on the line where I am trying to set a new password.

Basically I want to turn off the password in the "target" database. Then
from the "source" database export a number of queries to tables into the
"target". Then I was going to reopen the "target" database and reset the
password back to the original.

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:\policy database\publish files\data viewer-current.mdb"
Set acc = New Access.Application
acc.Visible = True
Set db = acc.DBEngine.OpenDatabase(strDbName, False, False,
";PWD=Phillies")
acc.OpenCurrentDatabase strDbName
db.NewPassword "Phillies", ""
db.Close
Set db = Nothing
acc.Quit

End Sub
 
D

Dkline

Figured it out by looking at the Object Browser. Set "options" to True
instead of False.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top