Combobox

dr223

Registered User.
Local time
Today, 00:45
Joined
Nov 15, 2007
Messages
219
Hallo,

Simple question, is their a way of showing the value on the combo box without saving it in a table. Therefore, when you open the form again next time the value last selected is viewed again.

Thanks
 
That doesn't exactly make sense. If you want the ComboBox to "remember" what was last selected, then you have to store at least the index of the ComboBox somewhere, and the best place to do that is in a table. The easiest way to do this is to make a "ControlSettings" table where you store the values of the various ComboBoxes, Listboxes, etc. It might look like this:

Code:
[b]t_Control_Settings[/b]

[u]FieldName[/u]      [u]FieldType[/u]
ComboBox1      Number (Integer)
ListBox1       Number (Integer)
Textbox1       Text
CheckBox1      Boolean
.              .
.              .
.              .

Now, set the table t_Control_Settings to be the RecordSource for your form, and tie each control's control source property to the matching FieldName. If you'd rather store the actual content of the Combo/Listboxes, that's fine. It's just less room if you store the index, but it can perhaps be a little more confusing, depending on your skill level.

There are other ways of doing this. If your form already has a different control source, then you set each control's AfterUpdate event to write the changes to your Control Settings table, like this:

CurrentDb.Execute "UPDATE t_Control_Settings SET ComboBox1 = " & ComboBox1.ListIndex

Or, for text instead of the index number (Note that this assumes your Bound Column is the text to store):

CurrentDb.Execute "UPDATE t_Control_Settings SET ComboBox1 = '" & ComboBox1 & "'"

You could use global variables, although that's not at all recommended because it's overhead, and the control values are lost once the database is closed.

You could do a number of other things but the important part to get from this is that if you want the controls to "remember" the last user input, then that user input has to be stored somewhere where it can be retrieved.
 

Users who are viewing this thread

Back
Top Bottom