I'm deleting Table Links in code. One iteration through the process leaves some tables still there. This was fixed by an outer "FOR i = 1 to 4" loop, but this isn't a pristine solution.
Any insight into why this code leaves some linked tables still in the TDefs collection?
[tt]
Private Sub DeleteLinks()
On Error GoTo Error_DeleteLinks
Dim Db As DAO.Database
Dim Tdf As DAO.TableDef
Dim strTable As String
Dim intCount As Integer
Set Db = CurrentDb
For Each Tdf In Db.TableDefs
If Len(Tdf.Connect) Then
strTable = Tdf.Name
Db.TableDefs.Delete strTable
Db.TableDefs.Refresh
End If
Next
Exit_Error_DeleteLinks:
Exit Sub
Error_DeleteLinks:
Debug.Print Err.Number & vbTab & Err.Description
Resume Exit_Error_DeleteLinks
End Sub
[/tt]
Any insight into why this code leaves some linked tables still in the TDefs collection?
[tt]
Private Sub DeleteLinks()
On Error GoTo Error_DeleteLinks
Dim Db As DAO.Database
Dim Tdf As DAO.TableDef
Dim strTable As String
Dim intCount As Integer
Set Db = CurrentDb
For Each Tdf In Db.TableDefs
If Len(Tdf.Connect) Then
strTable = Tdf.Name
Db.TableDefs.Delete strTable
Db.TableDefs.Refresh
End If
Next
Exit_Error_DeleteLinks:
Exit Sub
Error_DeleteLinks:
Debug.Print Err.Number & vbTab & Err.Description
Resume Exit_Error_DeleteLinks
End Sub
[/tt]