Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables in forms...

Status
Not open for further replies.

mike777

Programmer
Jun 3, 2000
387
US
How do I get the value of a variable in one form over to another form?
For example, let's say Form1 has a variable in its class module called MyVar1. How can I get that value over to the class module section of Form2?
I tried creating a module, where I declared a new variable (NewVar) at the module level. Then I wrote a Sub Procedure that assigned the public variable the value of MyVar1 (the procedure was called from Form1).
Thing is, I can tell that the application is holding the value of the NewVar as long as the code is running, but when I make refernce to NewVar (e.g. Msgbox NewVar) from Form2, it is empty, or says I have to declare the variable if Option Explicit is set.
Forgive me is I am rambling. I don't feel that I really know how to explain my issue very well. ANy help you can provide is very much appreciated.
 
You will have to keep form1 open where you set you variable, and open form2

I would store the value in a hidden field in unbound Text Box and then close form1, you can then refer to the value once it is stored in form2.
 
I would create a module calles mdlGlobals and all I would have in it are public variables.

public NewVar as Variant

but no code.

In the code for form 1 change it to mdlGlobals.NewVar=MyVar1

then in form 2 you can use that variable

msgbox(mdlGlobals.NewVar)

at least I am assuming you can do this (it's late at night, I'm a little sleepy, so don't shout at me if I'm wrong!)

If that doesn't work have a hidden form open all the time with the public variable on it. I know this works! I use it!

B ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
This looks great. Thanks for the help. I'll try the Public thing out and report back.
-Mike
 
OharaB: That works great. That's exactly what I was looking for. Guess you should work late more often. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top