Using a public variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am declaring a public variable in the declarations section of a form's
module, and assinging it a value in a private sub in that module. I would
like to use the variable in a module for another form, but the variable loses
it's value. How do I deal with this?
 
Declare the variable in a stand-alone module (as opposed to in the form's
module)
 
In
Wavequation said:
I am declaring a public variable in the declarations section of a
form's module, and assinging it a value in a private sub in that
module. I would like to use the variable in a module for another
form, but the variable loses it's value. How do I deal with this?

To refer to a public variable in a form module (or any class module)
form outside that module, you have to qualify the reference with a
reference to the (loaded) object containing the variable. So if you
define public variable varX in form Form1, if you want to refer to it
from Form2 your reference will be like this:

Forms!Form1.varX

Form1 must be open at the time that reference is evaluated.
 
Back
Top