I have the following script that either converts a single linked table to a local table or ALL linked tables to local tables, however I am getting the following 2 error messages on several tables for the ALL tables script.
error 3709, the search key was not found in any record
Error 3300, cannot create a relationship.
error 3709, the search key was not found in any record
Error 3300, cannot create a relationship.
Code:
Sub Convert_Linked_Tables_To_Local()
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Set dbs = CurrentDb
GoTo Multi1
'================================================================================
'INDIVIDUAL TABLE
Dim SingleTable As String
'THE FOLLOWING LINE IS THE ONLY LINE THAT YOU NEED TO CHANGE FOR A SINGLE TABLE
SingleTable = "CS - Agent abbreviations"
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.Name = SingleTable Then
'Debug.Print tdf.Connect
DoCmd.SelectObject acTable, SingleTable, True
RunCommand acCmdConvertLinkedTableToLocal
End If
End If
Next tdf
'COMMENT OUT THE FOLLOWING LINE TO USE FOR ALL LINKED TABLES
GoTo END1
'================================================================================
Multi1:
'ALL LINKED TABLES TO LOCAL TABLES
Dim MultiTable As String
For Each tdf In dbs.TableDefs
MultiTable = tdf.Name
' If the table has a connect string, it's a linked table.
If Len(tdf.Connect) > 0 Then
'Debug.Print tdf.Connect
DoCmd.SelectObject acTable, MultiTable, True
On Error GoTo ERR1
RunCommand acCmdConvertLinkedTableToLocal
End If
Next tdf
END1:
Exit Sub
ERR1:
Debug.Print "Error Number: " & Err.Number & " Table that Failed to convert: " & tdf.Name
Resume Next
End Sub