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.
