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

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
 
A

Allen Browne

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
 
J

Joe Fallon

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.
 
G

Guest

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






.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top