how to use relative paths for access linked tables

Dominic Raftery 0 Reputation points
2025-07-15T00:08:47.1966667+00:00

How can I set a relative path to an external linked table

Microsoft 365 and Office | Access | Development
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. George Hepworth 21,805 Reputation points Volunteer Moderator
    2025-07-15T00:38:46.3166667+00:00

    I do not think you can link a table using a relative path.

    You could, however, create a VBA procedure that would generate the required full path from the relative path and then relink the tables using that regenerated full path at startup.

    Is that something you'd be willing to consider instead? It wouldn't be that different from a lot of existing code that relinks tables on startup with the variation of figuring out the path from your relative path.

    0 comments No comments

  2. Duane Hookom 26,280 Reputation points Volunteer Moderator
    2025-07-15T00:42:01.4966667+00:00

    I assume you mean relative to the location of the target/current file. There are lots of code for relinking on the web. You can combine the code with currentdb.name to get the current location.


  3. TiNo-T 4,215 Reputation points Microsoft External Staff Moderator
    2025-07-15T10:04:08.1566667+00:00

    Dear @Dominic Raftery

    Thank you so much for contacting Microsoft Q&A Forum. 

    Based on your description, I understand that you want to set a relative path to an external linked table, the approach depends on the software or environment you're using. Assuming that you use Microsoft Access, which is common scenario, relative paths make your Access database portable, and you can move the folder to another location or share it with others without breaking the links. Access itself stores absolute paths by default when you link external tables. To convert them to relative paths, you need to use VBA. 

    Here is an example scenario: 

    • Your main Access file: MainDB.accdb 
    • Your linked file: Data\ExternalData.accdb 
    • Both are in the same root folder, with the linked file in a subfolder. 

    Example VBA Code to Relink using a Relative Path: 

    Sub RelinkToRelativePath()
        Dim db As DAO.Database
        Dim tdf As DAO.TableDef
        Dim newPath As String
        Dim tableName As String
    
        tableName = "YourLinkedTableName" ' Change this to your actual table name
        newPath = CurrentProject.Path & "\Data\ExternalData.accdb" ' Adjust relative path
    
        Set db = CurrentDb()
        Set tdf = db.TableDefs(tableName)
    
        If tdf.Connect <> "" Then
            tdf.Connect = ";DATABASE=" & newPath
            tdf.RefreshLink
            MsgBox "Table relinked to: " & newPath
        Else
            MsgBox "Table is not a linked table."
        End If
    End Sub
    
    

    Also, Microsoft provides official documentation that supports the method of using VBA including using relative paths in Access databases. You can consult more in these articles: 

    I hope this information can help you and please kindly correct me if I misunderstand your concern. 

    Wish you a pleasant day!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    User's image


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.