As a lot of my projects involve using an odbc linked backend data source I have found this piece of code to be very useful. I usually trigger it to run on system startup like in AutoExec macro. It avoids any difficulties down the road with broken links and if the DSN name or database server changes then the only edit that needs to be made is to the connection string.
Note: If you have other linked tables aside from those connected by odbc you would have to allow for them in the code.
As usual all advice, critique and enhancements welcome :)
Mary
Code:
Function relinkTables()
Dim tdf As DAO.TableDef
For Each tdf In CurrentDb.TableDefs
' check if table is a linked table
If Len(tdf.Connect) > 0 Then
tdf.Connect = "odbc connection string to the DSN or database"
tdf.RefreshLink
End If
Next
End Function
As usual all advice, critique and enhancements welcome :)
Mary
Comment