Okay, how do I reference an object? Like an ADO object instantiated on Form1, but I want to reference it on Form2? ----------------------------------------
Is George Lucas Kidding...
I tried your suggestion of using the form name with the variable name (i.e. form1.varA), but it doesn't seem to work. ----------------------------------------
Is George Lucas Kidding...
Youngguy was right on track, but he forgot to tell you to make the form's variable Public. Then the variable can be accessed from anywhere in the program, just like all the other form properties:
'In form called frmMain:
Public MyVar as Integer
Form_Load()
MyVar = 3
End Sub
'In module:
Public Sub Main()
Debug.Print frmMain.MyVar 'Displays 0
Load frmMain
Debug.Print frmMain.MyVar 'Displays 3
End Sub
This works for variables and controls.
This can be a better approach than using a global variable in a module, because it allows you to use the same variable name for several forms. Just specify which MyVar you need using the form.variable syntax.
BTW: You can also make user-defined subs and functions public within a form. Call them the same way you'd use the variable:
frmMain.DoMySubroutine
Hope that helps!
-Mike
Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
For an extensive coverage of the subject refer to faq222-400 or thread222-37333 _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.