Click to See Complete Forum and Search --> : passing variables between forms


bschultz
June 15th, 2001, 11:29 AM
I am trying to pass a variable between two forms in an application. I have declared the variable (strStation) as public in module1. What I am trying to accomplish is when the user clicks on the "View" menu, he can scroll down to "Station Number" and when he clicks on it a pop-up window will appear asking him to enter a station number. Upon entering the station number and pressing the enter key, I would like the pop-up window to close, and transfer the station number the user entered to a text box on the User interface. I have everything working - except for getting the station number to appear on the user interface form. HELP!

Ghost308
June 15th, 2001, 11:50 AM
Okay, there is a pretty simple way to do what you're wanting, but there is an even easier way as well. The way you describe, you would need to make a reference to the variable on the popup form something like this...

Popupform!Text1.Text

where Popupform is the name of the popup window and the variable you are passing is the text in Text1. For more info on that style of variable referencing, look up some info on collections.

An easier way to do this would be to use an InputBox. When the user selects the item from your menu, instead of creating your own form for them to choose from, use somethin like this...

mnuItem_Click()
RetVal = InputBox("What do you want to look up?", "Title of InputBox")
'use the RetVal in your code to process whatever
End Sub

The disadvantage of the second method is that you can't set a pre-defined list of data for the user to choose from... at least as far as i know you can't. Hope that helps some!

phunkydude
June 15th, 2001, 11:54 AM
If the strStation var is declared public in a module and you set it from the Popup window, why not navigate to the User Interface form and get the strStation. It's public, so if you use the same var name, strStation, you'll be referencing the correct thingy.
If however you've declared it public in a Form's module, then reference it like thisform1.strStation

John G Duffy
June 15th, 2001, 01:05 PM
The textBox in the User Interface form should be directly addressable. Something like this.

Form1.Text1.Text = strStation
Form1.Show ' Make sure its visible



You can send the users selection to the interface form. In the sample of course, supply the name of your form and textbox

John G