Connecting to database using DAO

F

franky

I'm attempting to connect to a password protected MS Access database. The
following line works:

Set dbLink = DBEngine(0).OpenDatabase("C:\junk\Media_be1.mdb", False, False,
"MS Access;PWD=test")

However, if I try putting the database path in a variable called strNewPath
and setting the OpenDatabase method to this new database path I get an error:

strDBPath = strNewPath & """" & ", False, False, " & """" & "MS
Access;PWD=test"
Set dbLink = DBEngine(0).OpenDatabase(strDBPath)

I get an invalid file name error. How should the varible string look like
for the OpenDatabase method for a password protected MS Access database?
I've tried so many different ways and still unable to connect.

Thanks in advance!
 
K

Ken Snell [MVP]

In this code step:

Set dbLink = DBEngine(0).OpenDatabase("C:\junk\Media_be1.mdb", False, False,
"MS Access;PWD=test")

Each of the arguments (the items separated by the commas) are separate
entities and ACCESS expects to see them as such.

But when you try to do this:

Set dbLink = DBEngine(0).OpenDatabase(strDBPath)

All you're passing to the method is a single argument -- strDBPath -- which
corresponds to the path to the file. Your step leaves out all the other
arguments. In other words, you can use a variable for each argument, but you
cannot use a single variable to be all arguments.
 
F

franky

Thank you. That solved it.



Ken Snell said:
In this code step:

Set dbLink = DBEngine(0).OpenDatabase("C:\junk\Media_be1.mdb", False, False,
"MS Access;PWD=test")

Each of the arguments (the items separated by the commas) are separate
entities and ACCESS expects to see them as such.

But when you try to do this:

Set dbLink = DBEngine(0).OpenDatabase(strDBPath)

All you're passing to the method is a single argument -- strDBPath -- which
corresponds to the path to the file. Your step leaves out all the other
arguments. In other words, you can use a variable for each argument, but you
cannot use a single variable to be all arguments.
 

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