DCrake
Remembered
- Local time
- Today, 10:04
- Joined
- Jun 8, 2005
- Messages
- 8,632
I have a split database that may need tables to be relinked. I have proven code that does this. See Below. Anyway on this machine I do not have LTM enabled - must not have selected it when installed on machine. Anyway the code is failing and not refeshing the links. Could this be to do with the fact the LTM is not enabled? Has anyone come acrosss this before?
Code:
Function RefreshLinks(MyDatabase As String) As Boolean
' Refresh links to the supplied database. Return True if successful.
' Attempts to connect to mdb named in the jetdatapath setting
' Application fails if mdb not found
' This demo assumes that all the linked tabled appear in the same back end
' Code will need to be manipulated if using side ends.
' Also need to ensure that Miscrosoft DAO 3.6 Object library is referenced
'/Display message on status bar
DoCmd.Echo True, "Refreshng table links, please wait..."
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim ServerPath As String
'/Does the path exist
If Dir(MyDatabase) = "" Then
MsgBox "Cannot find source database. Please contact system support", vbCritical + vbOKOnly, "Application Failed"
DoCmd.Quit
End If
' Loop through all tables in the database.
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
' If the table has a connect string, it's a linked table.
If Len(tdf.Connect) > 0 Then
If tdf.Connect <> ";DATABASE=" & MyDatabase Then
tdf.Connect = ";DATABASE=" & MyDatabase
Err = 0
On Error Resume Next
tdf.RefreshLink ' Relink the table.
If Err <> 0 Then
RefreshLinks = False
Exit Function
End If
End If
End If
Next tdf
DoCmd.Echo True, "Done"
RefreshLinks = True ' Relinking complete.
End Function