Determining Database Folder Location

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.
 
D

Dirk Goldgar

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.
 
C

Craig

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?
 
D

Douglas J. Steele

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.
 
C

Craig

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!
 
D

Douglas J. Steele

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.
 
C

Craig

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.
 
C

Craig

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!
 
Top