Skip to content
Advertisement

Cycling through Table Defs and Deleting

I have a subroutine that runs on a local copy of a database and a network stored master.

To allow users to run my Excel add-in offline, I create a local version that has the same table names as the master but with only the relevant fields.

The first sub does not give any errors however when I reviewed the local database to ensure that the tables were being deleted and recreated, only 2 of the 4 tables were being deleted.

I developed a work-around, but I’d like to know if there is something I missed or did incorrectly or is this just a quirk of working with Access databases via DAO?

First Sub (only deletes 2 tables instead of all 4):

Second Sub (work-around):

Advertisement

Answer

You often get odd results when looping over a collection and deleting/adding items. Your second approach avoids that, as would looping backwards numerically through the collection e.g.

Alternatively just try to delete each definition and ignore any errors:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement