Access Tip of the Day

Return the name of the folder that stores an application

You may occasionally want to use VBA to determine the name of the folder that an active Access application is stored in. For instance, you may want to use that folder as the default location for data that's exported. To determine the folder in Access 2000/2002, use the CurrentProject object's Path property, as in:

strFolderName = Application.CurrentProject.Path

If you're using Access 97, you'll need to take a less straightforward approach. The same value can be calculated using the expression:

strFolderName = Left(CurrentDb.Name, _
Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))

Note that this expression will leave a slash after the last folder name, whereas the CurrentProject.Path approach doesn't. If you want to exclude the slash, change the expression to:

Left(CurrentDb.Name, _
Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))-1)

(Content provided by Element K Journals)

(Note: Your browser is set to refuse cookies. As a result, you may frequently see previously-viewed tips)
PrintPrint CloseClose

Copyright © 2001 - 2022 MJ Technologies, LLC.  All rights reserved.