how to set database password with DAO

T

TNL

Hi,
I want to use DAO to set password for my access 2000 database. How can I do
it?
Is it possible? If not, how can I with access (application), but over code
(vba).

Thanks
TNL
 
D

Dirk Goldgar

TNL said:
Hi,
I want to use DAO to set password for my access 2000 database. How
can I do it?
Is it possible? If not, how can I with access (application), but over
code (vba).

Thanks
TNL

Are you talking about the Database Password, as opposed to user-level
security passwords? If so, you can do it with code in the database like
this:

'------ start of code ------
Sub SetPassword()

Dim db As DAO.Database

Set db = CurrentDb()
db.NewPassword "", "snark"
db.Close

Set db = Nothing

End Sub

'------ end of code ------

Note, though, that the database must be opened exclusive, not in shared
mode, to run the code. Also, if upi are changing the password, noty
setting it for the first time, you must specify the old password where
the above code has "".

With suitable changes, you could use similar code to change the password
from outside the database.
 
T

TNL

Thanks

But, How can I open a database with protected password? I found only,
opening a database with workspace, but we can only create workspace object
with username and password, I can not specify database PW. With method
opendatabase, I tried:
Dim ws As DAO.Workspace
Set ws = DBEngine.CreateWorkspace("test", "admin", "")
ws.OpenDatabase "c:\db.mdb", True, , "pwd=11111"
or
ws.OpenDatabase "c:\db.mdb", True, , "database password=11111"

but it doesn't work.
Thanks
 
D

Dirk Goldgar

TNL said:
Thanks

But, How can I open a database with protected password? I found only,
opening a database with workspace, but we can only create workspace
object with username and password, I can not specify database PW.
With method opendatabase, I tried:
Dim ws As DAO.Workspace
Set ws = DBEngine.CreateWorkspace("test", "admin", "")
ws.OpenDatabase "c:\db.mdb", True, , "pwd=11111"
or
ws.OpenDatabase "c:\db.mdb", True, , "database password=11111"

but it doesn't work.
Thanks

Sorry for the delay in getting back to you. Try this:

Dim ws As DAO.Workspace
Dim db As DAO.Database

Set ws = DBEngine.CreateWorkspace("test", "admin", "")

Set db = ws.OpenDatabase("c:\db.mdb", True, False, ";pwd=11111")

I believe that you have to specify all the arguments in the OpenDatabase
call, up to the last one you actually use. That is, you can't say
ws.OpenDatabase("c:\db.mdb", , , ";pwd=11111")
 
T

TNL

thanks

Dirk Goldgar said:
Sorry for the delay in getting back to you. Try this:

Dim ws As DAO.Workspace
Dim db As DAO.Database

Set ws = DBEngine.CreateWorkspace("test", "admin", "")

Set db = ws.OpenDatabase("c:\db.mdb", True, False, ";pwd=11111")

I believe that you have to specify all the arguments in the OpenDatabase
call, up to the last one you actually use. That is, you can't say
ws.OpenDatabase("c:\db.mdb", , , ";pwd=11111")

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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