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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing values in subroutines, creating default values from storage 1

Status
Not open for further replies.

BotCow

Programmer
Jul 10, 2003
58
US
Okay I'm a C++/Java guy so I might have the wrong idea on how subroutines work. Anyway I have a combo box drop down menu that is assigned to a string variable 'tblName'. I want to "pass" this string into a function for storage so when the form containing the combo box closes, it will automatically set the last value used to be the default value.

eg. Open form, combo box value is set to "Donkey", set combo box value to "Cows", set combo box to "Horses", close form, open form, now "Horses" will be the default combo box value.

Do I have the right idea about passing it into a function and storing it? Or is there an easier way to do this.
 
There's no need to do it in a function. Create a new module (name it something like basPublicDeclarations) and declare all of your public (global) variables here, including the selected value of the combo box. For example,

Public gstrComboBoxValue As String

Then, in the on open event of the form that contains the combo box, set the combo box value to gstrComboBoxValue. Something like this:

if (len(gstrComboBoxValue) > 0) then cboYourComboBox.Value = gstrComboBoxValue

In the AfterUpdate event of the combo box, set the global variable equal to the value of the combo box. Like this:

If (Not IsNull(cboYourComboBox)) then gstrComboBoxValue = cboYourComboBox.value

 
Ahh okay, that's very cool. Thanks Fancy. You get a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top