First the form, I have a combo box called year_combo and a button called command2.
When you click the button, first it checks to make sure a value has been selected (saves that null error - very irratating). Then it assigns the selection to the variable The_Year.
To make a value stay until the Database is closed can be achieved a couple of ways, write to a table, public...And so on..However, I create a module and call it 'globals' then I have a complete list of what I have set.
Under this module I have put Global The_Year as String. String may not be the appropriate variable, maybe interger or something else.
Then any other forms that need this value, you just ask for The_Year value..
In the Form
Private Sub Command2_Click()
If IsNull(Me.Year_Combo) = True Then MsgBox "Please select a year!", vbOKOnly + vbInformation, "No selection": Exit Sub
The_Year = Me.Year_Combo
Hammbakka, your code works, but only when the form is active.
Ken, I tried what you said, but still have an issue. I want the combo box to default to the value selected by the user, when he closes the form.
I guess the way out would be to have a combo box (year_combo) in the form having ControlSource as the Global declaration (The_Year As String) and with the RowSource getting from a table of all possible years.
My problem is:
How can I have the combo box ControlSource pointing to a Global declaration and store its literal value?
The Main form has a combo (main_combo) the other form has a combo (year_combo). There is also a module called globals.
If you open the Main form and alter the year, it will allocate The_Year to your selection. Then when you press the command button to open the Other form, it changes the value of that combo on the new form to The_Year
If you alter the date of this combo on the new form and close it to return to the main form, the combo box on the main will select The_Year when opened.