Smartin said:
Yes, the declaration is in a normal module. Without meaning to be
argumentative, explain when should object TheClass die? The module does
not "close". It merely exists, and no code is fired to instantiate the
object. In better days I could probably have given a better explanation.
I hope this makes sense.
I will look into this a little further to be sure, but AFAICT the
instantiation of the class persists as long as the application is open.
Kind Regards,
Just to follow up and (hopefully) clarify, a publicly declared object is
accessible to the application for the life of the application. Unless,
of course, you set the object to Nothing.
Think of a publicly declared variable. It doesn't go away even though
the code asking for it is in another class/form/module.
Getting off topic somewhat, I would be interested to hear comments on
the virtues and pitfalls of using a class vs. a collection of variables
and functions in a module.
Personally, when I have a group of processes I want to apply to a
"thing" I like to create a class for it. I can swiftly reuse the code if
I need to use the "thing" in another application -- I simply drop in its
class module.
In the long run I find it is much easier to have the thing's methods and
properties on hand by typing a dot, rather than try to recall what Subs
and Functions are available. Plus, if I want to have multiple "things"
at the same time, a class makes this a snap.
For instance one "thing" I've been reusing quite a bit lately is
basically a text container I use to build up email messages in Access.
VBA and A97 do not provide a very robust collection of text manipulation
features, so I built functionality into the class like search and
replace, a tabulation mechanism for aligning columns of data, append,
automatic insertion of CrLf, etc. This reduces the amount of code I have
to write later -- and cleans up the code considerably.
HTH