Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use App.Path in VBA?

Status
Not open for further replies.

martiros

Technical User
Feb 1, 2003
113
US
I'm trying to get a path to the folder where my mdb file is.
I don't want ot use an absolute path because this DB will be distributed to many employees.

For now I'm using :

Dim strcurrent As String
strcurrent = CurrentDb.Name
strcurrent = Replace(strcurrent, "DB.mdb", "")

Why App.Path gives me an error?
Do I need to set any library references?
I've set ADO 2.5

Thanks
 
This will work for Access 2000 and above and no need to set any References:

Dim strThisDBPath as string
strThisDBPath = Application.CurrentProject.Path

I think this will work in '97, 2000 and above:

Dim strThisDBPath as string
strThisDBPath = CurDir
 
Thank you very much, I'll try it.

So, there is no App.Path in VBA then?...
Strange, in VBS the is a Server.MapPath() method - I thought that VBA should have something similar...
 
billpower,
for some reason your method returns me C:\MyDocuments directory for any mdb file locations.
My mdb file was in
C:\Inetpub\
???
Another question.
How do I use relative path in

Set pth = fs.GetAbsolutePathName("") ?
Anything I type between "" doesn't work


Set pth = fs.GetAbsolutePathName("try.mdb") - / \ ?

Thank you
 
The code I posted above has always reported the Current Application Path, just tested it calling from 3 different DBs in different directories:

Dim strThisDBPath as string
strThisDBPath = Application.CurrentProject.Path
Msgbox strThisDBPath

Help shows how to use GetAbsolutePathName, where you've put ("try.mdb") should be ("c:") if try.mdb is on the c drive and would return C:\Inetpub\ From what you said in your original post, if this DB could potentially be on any Drive, I think your wasting your time with GetAbsolutePathName. But then I could be wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top