home

Find Current Directory

Monday, March 24, 2003 08:14:30
Derived from comp.databases.ms-access from September 10th 1998 to October 20th 1998

To derive the current directory where your database is located in:

  • Create a new module, name it basCurrentDir
  • Type in the following code:
    
    '******************** Code Begin ****************
    'Code courtesy of Terry Kreft
    Function CurrentDBDir() As String
    Dim strDBPath As String
    Dim strDBFile As String
        strDBPath = CurrentDb.Name
        strDBFile = Dir(strDBPath)
        CurrentDBDir = Left(strDBPath, Len(strDBPath) - Len(strDBFile))
    End Function
    '******************** Code End ****************
    
    

    Note: if you have problems with the code, try tweaking the next to last line to read:

    CurrentDBDir = left(strDBPath, InStr(strDBPath, strDBFile) - 1)

    That is how the code originally was written, subsequently it was changed to what it is now when a particular bug was discovered.)