VBA code could not find file

M

MeSteve

I am using the code shown as an example in the help files and when run, it
cannot locate the file.

Dim dbsProjects As Database
Set dbsProjects = OpenDatabase("Projects.mdb")

Why can VB not find the open database?
 
D

Douglas J. Steele

Try putting the full path to Projects.mdb, rather than just the file name.

That statement would only work if Projects.mdb happens to be in whatever
folder is the current directory. Predicting what Access considers to be the
current directory can be difficult: it depends on how you opened the
application.
 
D

Dale Fye

Steve,

1. Is this code in the "Projects.mdb " database? If so, you can refer to
the database using the currentdb object.

Set dbsProjects = currentdb

2. If not #1, then is this mdb supposed to be in the same folder where the
mdb containing the code is located? If so, try

Set dbsProjects = OpenDatabase(currentproject.path & "\Projects.mdb")

3. If not #2, then you will need to provide a path to the database as well
as the file name.

HTH
Dale
 
M

MeSteve

I did end up changing it to CurrentDb

Dale Fye said:
Steve,

1. Is this code in the "Projects.mdb " database? If so, you can refer to
the database using the currentdb object.

Set dbsProjects = currentdb

2. If not #1, then is this mdb supposed to be in the same folder where the
mdb containing the code is located? If so, try

Set dbsProjects = OpenDatabase(currentproject.path & "\Projects.mdb")

3. If not #2, then you will need to provide a path to the database as well
as the file name.

HTH
Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

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