Combo NOT showing Default

  • Thread starter Thread starter Charles D Clayton Jr
  • Start date Start date
C

Charles D Clayton Jr

A2K

I needed a combo box to remember the last value a user selects and
make that the default value so that next time they open the form it
will already have that value in the combo box. I searched the
archives and found this code:

Me.cboTest.DefaultValue = """" & Me.cboTest.Value & """"

I put it in the AfterUpdate Event but nothing works. I select a value
and then close out the form and then reopen and there is nothing in
the combo box displayed. If I should put a value in the Default
setting for the properties, then it works just fine but not from code.
I re-searched the archives and everyone seems to agress that this
would work. The only additional information I found was something
that said "default values" are only for new records.

Can anybody suggests why this is not working? Or give another
suggestion on how to solve me problem?

Thanks,

Charles D Clayton Jr
 
The DefaultValue property is applied only when you move to a new record. It
does not apply to existing records that have no value.

If you set the property while the form is open (not in design view), the
setting applies only while the form is open (i.e. it is lost when you close
the form).

The code should also test to make sure the Value is not Null before
attempting the assignment.
 
No. What you got will carry the last-entered value to the next new Record
in the *current session* of the Form and won't work when you close and
re-open the Form.

To change the DefaultValue (*for new Records*) dynamically from one session
of the Form to the next session, create a one-Record Table to hold the
last-selected value. Use the ComboBox_AfterUpdate to update this value in
the Table.

In the Form_Open (or Load) Event of the Form, use code to retrieve this
value and change the DefaultValue of the ComboBox to this value.
 
Hi,
That code will only work while the form is open.
If you want to remember the value when the form is closed, you'll have to
save the value in a global variable (a public variable declared in a
standard module).
If you want the value to persist even when your entire application is
closed, you'll
have to write it to a table and retreive it when you db opens.

HTH
Dan Artuso, MVP
 
Thanks for all the responses. It really helped and increased my
understanding.

Van, you outlined a way to dynamically change the defaultValue. I was
able to create a table and update that table from the
Combo_AfterUpdate Event but I cannot seem to figure out how to
retrieve that info from the table. I am trying to do everything now
with ADO. Could you provide some code to do this or point me in the
right direction?

Thanks,

Charles D Clayton Jr
 
I wrote in the previous post that you would need to use the Form_Open or
Form_Load to retrieve this value and assign as the DefaultValue.

You can simply use DLookUp to retrieve the value.

Note that regardless of the data type of the bound Column, the DefaultValue
is always of Text type.
 
Back
Top