Using DAO to display tables, not all are displayed ???

  • Thread starter Thread starter Acie
  • Start date Start date
A

Acie

I use the following code below, to basically display all of
the tables that exist in the given database. But
inevitably, it display all of them except for one table
(not always the same table). Anyone know why ??? (If I run
the code twice, then all the tables are displayed and thus
deleted according to the expressed criteria). But I
shouldn't have to run this more than once!

(Actually I use the code and then I delete the tables that
match a certain criteria).

Code:

Dim tdf as Tabledef
Dim dbs as database

Set dbs=currentdb

With dbs
For each tdf in .Tabledefs
if tdf.Name like userid & "*" then
.tabledefs.delete tdf.name
end if

next tdf
End with


Any ideas???
Thanks,
Acie
 
Since you are deleting tables, the For... Each... may be confused. Try
looping backwards through the tables:

For i = tdf.Count - 1 to 0 Step -1
If ...
.tablddefs(i).delete tdf.name
End If
Next
 
You can't delete tables and expect the indexes to stay the same!
They get re-numbered.

That is why the tip for looping (for the last 10 years) has been:

Loop Backwards if you want to delete items from a collection to avoid
re-setting the indexes on the remaining values.
 
Thanks for the reply. Will try looping backwards..
-----Original Message-----
You can't delete tables and expect the indexes to stay the same!
They get re-numbered.

That is why the tip for looping (for the last 10 years) has been:

Loop Backwards if you want to delete items from a collection to avoid
re-setting the indexes on the remaining values.
--
Joe Fallon
Access MVP






.
 
Back
Top