VBA code could not find file

  • Thread starter Thread starter MeSteve
  • Start date Start date
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?
 
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.
 
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
 
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.
 
Back
Top