Deleting Objects Using VBA

U

Ulrich1947

hi to everybody,

I do have a problem administering my BE/FE Application (Windows 2000
Professional, Access 2000): When closing my application, I would like to
delete quite a number of various objects (such as tables, queries, forms,
reports, modules) - most of them embedded or imported, some created. Which
objects are to be deleted is defined in a table called "basImport" containing
all information which way an object should be treated (Sometimes this even
varies from user to user).

I am trying to do this by a separate For ... Each Routine for each Group of
Objects, in which name after name is defined and subsequently the object (e.
g. a Form) is deleted by "DoCmd.DeleteObject acForm, obj.Name".

However, not all Forms (same applies for some Reports and som Tables) are
deleted allthough they should be. Running the procedure step by step it runs
correctly through the For ... Each Routine but in some cases (the last ones,
whereever they may start) the obj.Name cannot properly defined (It states
something like "Object Variable not properly defined or does not exist". As
the procedure includes an Error-Routine it slips just over te problem and
leaves the object unremoved.

Do I have to refresh the e. g. Forms-Listing after each deletion and how can
I do this ?

Is there anybody out there ?

who could help me?

Many thanks in advance !

Ulrich
 
A

Alex Dybenko

hi,
yes, For ... Each will not work to delete objects you referring in the loop
I would suggest to open recordset, based on your basImport table, loop
through it and delete from there
 
J

John Spencer

Every time you delete an object in a collection, the remaining objects get
renumbered. Without seeing your code it is impossible to tell if this is
causing your problem or not.

If I want to delete all objects in a collection, I use a loop and start at
the highest number

For IntLoopCounter = ObjectType.Count-1 to 0 Step -1
'DELETE stuff here
Next IntLoopCounter
 

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