Determining Database Folder Location

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

When someone starts an application how do I determine the folder name that
the database file is in?

If the application is opened by starting Access, and clicking FILE, OPEN and
they point to the database file and open it, the CurDir returns the folder I
want. If they open the application by double clicking the database file the
folder CurDir returns the wrong folder.
 
Craig said:
When someone starts an application how do I determine the folder name
that the database file is in?

If the application is opened by starting Access, and clicking FILE,
OPEN and they point to the database file and open it, the CurDir
returns the folder I want. If they open the application by double
clicking the database file the folder CurDir returns the wrong folder.

In Access 2000 or later, CurrentProject.Path returns the folder.
CurrentDb.Name (in Access 97 or later) returns the folder path and file
name.
 
Thats cool.

But when I use TransferSpreadsheet, and other functions, in a macro it
requires a full path. If I could set the default folder that the database
is in, I could use relative paths not the FULL path in the filename
parameter.

Then when I copy an application to another PC it will work when people
double click the database file to start the application.

How can I do this?
 
Dirk's shown you how to determine what the path is: you can use that to
create the full path so that it'll always be correct, regardless of what
folder the database actually exists in.

If you're really determined not to do that, VBA has a built-in ChDir command
that lets you change the current directory. As far as I'm concerned, though,
it's always safer to use an explicit means of determining what folder you
want to use, rather than relying on current directory.
 
Using the ChDir worked! Thanks alot. That saved me lots of time.

I fully agree with you VBA is the proper way to go.

With all the macros it is quite a rewrite for the application I inherited.

Now they can copy the database file to any folder on any PC and it will work
until I can recode the TransferText etc. parts of the Macros in VBA. There
is a lot of importing and exporting going on.

Thanks!
 
Glad you're okay now.

My point, though, wasn't that VBA is the proper way to go (although, of
course, it is). You can use CurrentProject.Path in a macro just as easily as
you can in VBA.
 
How?


Douglas J. Steele said:
Glad you're okay now.

My point, though, wasn't that VBA is the proper way to go (although, of
course, it is). You can use CurrentProject.Path in a macro just as easily as
you can in VBA.
 
Thanks so much for all your help!

I am a newbie and didn't even know you could put formulas in the FileName
parameter box.

Access never ceases to amaze me in it's flexibility, maturity and
capabilities!
 

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

Back
Top