I use a modified version of Doug Steele's code for creating a DSN-less connection. I've added a stored procedure which returns a list of tables that can be linked to which is used as a recordset.
I make sure that there are actually tables in the list then proceed to delete all linked tables (only one ODBC source, so that's fine with me), but this doesn't complete the job properly, skipping some tables.
My code:
I just stepped through the code, and at one point, I had 8 tables total, 6 system tables, and two linked tables that should be deleted (and meets the criteria for doing so). If I play the code up to the line .MoveFirst, it deletes only one table, leaving me with still one linked table. Repeating the loop, it delete that last linked table, so code is essentially correct, but for some reasons it just doesn't does it. As a consequence, I will get an error when I try to append a new table because same table will still be there when it should have been deleted.
I'd like to say that it's because my computer is too fast, but that quite doesn't make sense. Or maybe I'm missing something obvious?
TIA.
I make sure that there are actually tables in the list then proceed to delete all linked tables (only one ODBC source, so that's fine with me), but this doesn't complete the job properly, skipping some tables.
My code:
Code:
With rst
If Not .BOF And Not .EOF Then
For Each tdfCurrent In dbCurrent.TableDefs
If Not Len(tdfCurrent.Connect) = 0 Then
dbCurrent.TableDefs.Delete (tdfCurrent.Name)
End If
Next
dbCurrent.TableDefs.Refresh
.MoveFirst
Do Until .EOF
Set tdfCurrent = dbCurrent.CreateTableDef(.Fields(0).Value)
tdfCurrent.Connect = strConnection
tdfCurrent.SourceTableName = .Fields(0).Value
dbCurrent.TableDefs.Append tdfCurrent
GenerateIndexSQL (tdfCurrent.Name)
.MoveNext
Loop
End If
End With
I just stepped through the code, and at one point, I had 8 tables total, 6 system tables, and two linked tables that should be deleted (and meets the criteria for doing so). If I play the code up to the line .MoveFirst, it deletes only one table, leaving me with still one linked table. Repeating the loop, it delete that last linked table, so code is essentially correct, but for some reasons it just doesn't does it. As a consequence, I will get an error when I try to append a new table because same table will still be there when it should have been deleted.
I'd like to say that it's because my computer is too fast, but that quite doesn't make sense. Or maybe I'm missing something obvious?
TIA.