Pages

Sunday, October 26, 2008

How to use App.Path in VBA

App.Path only works in Visual Basic, not VBA [Visual Basic for applications]. Use CurrentProject keyword for VBA.

CurrentProject object refers to the project for the current Microsoft Access project (.adp) or Access database (.mdb).

Getting the location to the current database using Access 2000/2002/2003...

'returns the database file name
CurrentProject.Name

'returns the database path
CurrentProject.Path 

'returns the database path and the file name
CurrentProject.FullName 

Getting the location to the current database using Access 97...

'returns the database file name
Dir(CurrentDb.Name) 

'returns the database path
Left(CurrentDb.Name,Len(CurrentDb.Name)-Len(Dir(CurrentDb.Name))) 

'returns the database path and the file name
CurrentDb.Name

'returns the directory that Access [msaccess.exe] is installed in
(SysCmd(acSysCmdAccessDir))

No comments:

Stats