Referencing Public variables in VBA

J

john burrow

Please help! I declare an integer variable as public
called "flag" in form1 and assigned a value of 1 to it
like:
flag = 1
But no luck when I tried to reference to it from another
form called form2 using
msgbox flag
 
N

Newbie

Have you tried declaring the variable in a separate module?

Module1
Public flag as integer

Form1
flag = 1

Form2
msgbox flag

HTH
Al
 
M

Marshall Barton

john said:
Please help! I declare an integer variable as public
called "flag" in form1 and assigned a value of 1 to it
like:
flag = 1
But no luck when I tried to reference to it from another
form called form2 using
msgbox flag


Since a form's module is really a class and its module level
Public variables are properties of the class, you would need
to use:
MsgBox Forms!Form1.Flag

On the other hand, if you moved the public variable to a
standard module, the code you have would work as is.
 
J

john burrow

Many thanks Marshall. It worked.
-----Original Message-----



Since a form's module is really a class and its module level
Public variables are properties of the class, you would need
to use:
MsgBox Forms!Form1.Flag

On the other hand, if you moved the public variable to a
standard module, the code you have would work as is.
 

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