It is a Best Practice to split your MS Access File between a Front-End MS Access Application and a Back-End MS Access Database this is to make your Software Maintenance easier but this comes with a little price: if you work on multiple computers at work and at home while not using the same directory, you may encounter the problem of broken links between the two parts.
Of course you can use MS Access Tool to rebuild the link but this is rather tedious so here’s a VBA script to do so automatically:
Public Function RelinkAllAccessTables(SourceDatabaseName )
Dim DB As DAO.Database
Dim RS As Recordset
Set DB = CurrentDb
SQL = "select name from MsysObjects where type = 6"
Set RS = DB.OpenRecordset(SQL)
RS.MoveLast
Debug.Print RS.RecordCount
RS.MoveFirst
i = 0
Do While Not RS.EOF
SourceTableName = RS(0)
Call RelinkLocalTable(SourceTableName, SourceDatabaseName)
RS.MoveNext
i = i + 1
Debug.Print i
Loop
End Function
The RelinkLocalTable essentially redefine the Tabledef Connect property to the new database path:
Public Function RelinkLocalTable(p_SourceTableName, p_SourceDatabaseName, Optional p_TargetTableName)
TablePath = CurrentProject.Path & "\"
SourceDatabaseName = p_SourceDatabaseName
Dim DB As DAO.Database
Dim RS As Recordset
Set DB = CurrentDb()
Dim tempTableDef As DAO.TableDef
If IsMissing(p_TargetTableName) Then
TargetTableName = p_SourceTableName
Else
TargetTableName = p_TargetTableName
End If
SourceTableName = p_SourceTableName
SourceDatabaseName = p_SourceDatabaseName
Set tempTableDef = DB.TableDefs(TargetTableName)
If tempTableDef.SourceTableName "" Then
tempTableDef.Connect = ";DATABASE=" & TablePath & SourceDatabaseName
tempTableDef.RefreshLink
End If
End Function
To use the RelinkAllAccessTables function just call for example:
call RelinkAllAccessTables("Northwind.mdb")
For more info see:
Automatic Table Relinking

Tags: msaccess vba relink programmatically, relink