Public Function RefreshTableLinks() As String
Dim remembered_path As String
On Error GoTo ErrHandler
Dim strEnvironment As String
strEnvironment = GetEnvironment
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strCon As String
Dim strBackEnd As String
Dim strMsg As String
Dim intErrorCount As Integer
Set db = CurrentDb
'Loop through the TableDefs Collection.
For Each tdf In db.TableDefs
'Verify the table is a linked table.
If Left$(tdf.Connect, 10) = ";DATABASE=" Then
'Get the existing Connection String.--
strCon = Nz(tdf.Connect, "")
'Get the name of the back-end database using String Functions.
strBackEnd = Right(strCon, (Len(strCon) - 10))
'Debug.Print strBackEnd
'Verify we have a value for the back-end
If Len(strBackEnd & "") > 0 Then
If Len(remembered_path) = 0 Then
'----------------------------------------------------------------
Dim res As Boolean
res = path_exists(strBackEnd)
If res = False Then
strBackEnd = getBackEnd_new_location
If Len(strBackEnd) = 0 Then
DoCmd.Quit
Else
remembered_path = strBackEnd
End If
Else
remembered_path = strBackEnd
End If
'-----------------------------------------------------------------
End If
'Set a reference to the TableDef Object.
Set tdf = db.TableDefs(tdf.NAME)
tdf.Connect = ";DATABASE=" & remembered_path
'Refresh the table links
tdf.RefreshLink
End If
End If
Next tdf
ErrHandler:
If Err.number <> 0 Then
'Create a message box with the error number and description
MsgBox ("Error Number: " & Err.number & vbCrLf & _
"Error Description: " & Err.Description & vbCrLf)
End If
End Function