Referencing Public variables in VBA

  • Thread starter Thread starter john burrow
  • Start date Start date
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
 
Have you tried declaring the variable in a separate module?

Module1
Public flag as integer

Form1
flag = 1

Form2
msgbox flag

HTH
Al
 
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.
 
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.
 
Back
Top