Unanswered: Display global variable value on forms
How do I best display the current value of a global variable on a form?
I intuitively set the control's Control Source = MyPublicVariable but that does not work. Instead I end up creating a function to call the variable's value and then set the control's control source = MyPublicFunction or I run private sub routines to populate unbound controls with the values.
The value of the public variable is in memory, can't I just show it on the form without using a function? I have forms with many such controls and the forms are loading slow due to many roundtrips looking for variable values.
I have gotten around this problem before by loading the values of public variables on a form at startup, keep it open while the application is running and calling the values from that form but it's a clumpsy method when the variable's value change often.
I don't think you can do that for local variables either. It is not about variable being global or local. You should either set control value in code or set control source to a function to show any variable in your code.
Last edited by ghozy; 09-21-04 at 13:59.
I declare my public variable in the code of the form (not a module) as: Public MyClassVariable As Integer. Put this string right on top of the form's code page under Option Explicit.
Then I set this variable by some event on the form (like Form_Open) as MyClassVariable = MyModuleVariable
Then in the control on the SAME form I bind the control's control cource =[MyClassVariable]. I could also use unbound controls and pass public variables in code as Me.control.value = MyModuleVariable but I would not see the function of the unbound control by just looking at it on the form's design view.
Either way with these two methods I don't have to use functions to get the public variable to show in the form.
My original problem was how to bind the control's control cource =[MyModuleVariable] directly without a function call but that is not possible.