Force combo box to validate limit to list

  • Thread starter Thread starter oraustin
  • Start date Start date
O

oraustin

Hi all, hope you can help because I'd ideally not like to mess around
too much with code to solve this one.
I'm using Access 97 on my form there's a bound combo box. Behind the
scenes in VBA I change the rowsource. If the value the combobox is
displaying is not one from the drop down list then I'd like an error
message.
The limit to list propery for the control is set to true but when focus
leaves the control the validation doesn't pickup that the field/control
value is not on the list. If however I manualy go to the control and
alter the text then the validation works fine.

Any ideas please :)
Oliver
 
Hi all, hope you can help because I'd ideally not like to mess around
too much with code to solve this one.
I'm using Access 97 on my form there's a bound combo box. Behind the
scenes in VBA I change the rowsource. If the value the combobox is
displaying is not one from the drop down list then I'd like an error
message.
The limit to list propery for the control is set to true but when focus
leaves the control the validation doesn't pickup that the field/control
value is not on the list. If however I manualy go to the control and
alter the text then the validation works fine.


Here's a couple of ideas you can explore.

The combo box's ListIndex property will be -1 if the item is
not in the list:
Me.combo.RowSource = " . . .
If Me.combo.ListIndex = -1 Then
' current item is not in the list

If you change the combo box's .Text property, it will
trigger all the usual events and (re)check the Validation.
This can be done by simply setting it to itself:
Me.combo.Text = Me.combo.Text
 
checking the listindex property was exactly what I needed - thanks very
much.
in return I can offer knowledge on two stroke motorbikes of the late
80s :)
 
Back
Top