Why did global work but public didn't?

Margarita

Registered User.
Local time
Yesterday, 19:13
Joined
Aug 12, 2011
Messages
185
Hello,
I am working in Access 2003, vba 6.5

In Form1, the user clicks one of two buttons, each button sets a different value to a public variable called manual_or_auto.

In Form2, the procedure of the Save Record button does stuff based on the value of manual_or_auto.

The only way I got this to work was by adding a new standard module and declaring manual_or_auto as global there. When I tried to declare the variable as Public in either the Form1 or Form2 code, it wouldn't work. The value from the Form1 procedure never got attached to the variable. The immediate window kept printing it as blank.

Why didn't a public declaration in either of these modules work? Shouldn't public work everywhere?

Thank you.
 
I believe Access considers Forms class objects so the code behind them probably behaves like a class module does, the public variable is available within form1, but not outside...unless you declare a form1 object, then you could access or assign data to/from the public variable.
 
I believe Access considers Forms class objects so the code behind them probably behaves like a class module does, the public variable is available within form1, but not outside...unless you declare a form1 object, then you could access or assign data to/from the public variable.

BUt isn't the very purpose of public variables to facilitate variable communication between class modules? If one class module can't read the variable that is declared as a public variable in another class module, then what is the purpose of declaring the variable as public? If only the first class module can read it, isn't that the same as just having the variable private in that module?

Thank you!
 
Public variables in Class Modules need to include the context.
formname.publicvariable
 

Users who are viewing this thread

Back
Top Bottom