MS Access VBA – Path of the Current Database

If all you wish is to determine the path of the current database, simply use the following line of code:

Application.CurrentProject.Path

It will return a string value like: ‘D:\MS Access\References’

Pay particular attention to the fact that it does not include the closing slash in the string it returns. So if you are going to use it in your code, remember to concatenate it with a closing slash by simply doing something like:

Application.CurrentProject.Path & "\"

5 responses on “MS Access VBA – Path of the Current Database

  1. Eric

    Application.CurrentProject.Path
    I have MS Access 2007
    I have found this statement works well for a “accdb” but I converted my database to a “accde” and it no longer works. Has anybody got any ideas of how to get round this problem.
    Thanks

    1. Daniel Pineault Post author

      I am unable to replicate the issue. The line Application.CurrentProject.Path work fine for me both in an accdb and accde. I would urge you to post this issue in a forum UtterAccess.com given more details:

      • How are you using the command
      • What error are you receiving
      • A repro database with the issue
      1. Eric

        Hi Daniel
        Perhaps it’s my poor code.
        Dim strPath1 As String
        Dim actualpath As String
        Dim stDocName As String
        Dim stDocName2 As String
        ‘The Location Path of the destination Link table. It’s logical that the Label Printer is not in the same place as the Table Storage.
        strPath1 = TextDest ‘Text box on the StartLabelPrinter form showing the path of the Table Storage

        ‘Opening the StartLabelPrinter form
        DoCmd.Maximize
        ‘The actual Path of the Front End
        actualpath = Application.CurrentProject.Path

        If actualpath = strPath1 Then
        Command31.Visible = True
        TextDest.Visible = True
        Label11.Visible = True
        Label13.Visible = True
        Else
        Command31.Visible = False
        TextDest.Visible = False
        Label11.Visible = False
        Label13.Visible = False

        ‘Sets up the forms for use
        stDocName = “printout”
        stDocName2 = “SENDER”
        DoCmd.OpenForm stDocName2, , , stlinkCriteria
        DoCmd.OpenForm stDocName, , , stlinkCriteria
        End If
        What I am doing here is hiding the Access menus etc. It’s the poor mans version of an “exe” file. I initially tried using Visual Studio but found it very different than the old Visual Basic and gave up.
        With my Access 2007 I’m finding it does exactly what I want it if it is a accdb file. After I convert it to accde file the ” DoCmd.Maximize” and “Application.CurrentProject.Path” doesn’t work. Interestingly this code worked as a accde worked well until I added the “Application.CurrentProject.Path”. In the accde format there is no error message, it just doesn’t work.
        Prior to adding “Application.CurrentProject.Path” I was manually adding the Database path.
        cheers
        Eric

  2. Eric

    Hi Daniel
    Thanks for getting back.
    What I’m doing in this bit of code is opening a blank form to hide the access directories then the active tables are visible on top. It’s my poor attempt to make up for Access’s inability to be made into an exe file. I tried Visual Studio but gave up in disgust 🙁
    This is the first bit of code as I open my Front End bit of my code.
    What I’m trying to do is when I close my database I’m making a copy of the tables to another location hence I need the table paths for both Front End with my visual basic code (accde) and Storage database (accdb).
    What I have found. Before I convert the Front End from accdb to accde my code works well. As soon as I convert to accde. DoCmd.Maximize does not maximize and Application.CurrentProject.Path does not provide a database path. The interesting thing is that it all worked well before I added “Application.CurrentProject.Path”. At that time I had a table and I was manually entering the Front End path and Storage path.
    I apologize for my poor code.

    Dim strPath1 As String
    Dim actualpath As String
    Dim stDocName As String
    Dim stDocName2 As String

    ‘The Location Path of the destination Link table. It’s logical that the Label Printer is not in the same place as the Table Storage
    strPath1 = TextDest ‘Text box on the form that is connected to a field on a link table
    ‘Opening the StartLabelPrinter form
    ‘ Maximizing the Form as a backdrop
    DoCmd.Maximize
    ‘The actual Path of the Front End
    actualpath = Application.CurrentProject.Path
    If actualpath = strPath1 Then
    Command31.Visible = True
    TextDest.Visible = True
    Label11.Visible = True
    Label13.Visible = True
    Else
    Command31.Visible = False
    TextDest.Visible = False
    Label11.Visible = False
    Label13.Visible = False

    ‘Sets up the forms for use
    stDocName = “printout”
    stDocName2 = “SENDER”

    DoCmd.OpenForm stDocName2, , , stlinkCriteria
    DoCmd.OpenForm stDocName, , , stlinkCriteria
    End If
    Cheers Eric