Using a public variable

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?
 
D

Douglas J. Steele

Declare the variable in a stand-alone module (as opposed to in the form's
module)
 
D

Dirk Goldgar

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.
 

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