Form temporary variables

D

DoctorG

I wish to declare temporary variables that will be declared when a form is
shown, will be visible to all form subroutines and "deleted" (so that memory
is released) after the form is hidden again. Is this possible?

If not what is the best way to declare variables visible to all form
subroutines? Public....????
 
R

Rick Rothstein

If you really meant "hide", as you said, rather than "close", then you can't
do what you want. To make a variable, global to your form, which will cease
to exist when the UserForm is **closed**, simply Dim it in the
(General)(Declarations) section of the UserForm's code window (that is, at
the top of the code window and outside of any other procedure).
 
J

JLGWhiz

When a form is loaded using the Show method, the variables contained within
the underlying code for the form and for the controls are all temporary.
Once the form is unloaded, all values of those variables are dumped from
memory. As Rick suggested, during design mode, you can use the View Code to
access the UserForm code module, where you can declare any variables at the
top of the module that you want to apply to any of the procedures within the
form and the controls it contains. Again, any variable declared within a
UserForm, its procedures and its controls' procedures are temporary. They
only last for the active life of the UserForm, although they will
re-initialize each time the form is loaded.
 

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