Excute Limit to List programatically

A

Angel G

I have a comobo box that get a value programatically, and I also set the
cursor to go to the combo box. All works well.
Howevere sometimes the value is not part of the list and if the user goes to
a different control The limit to list event does not fire up.
Can i fire it up on Lost focus?
This way I can verify that the value that was entered programatically is
part of the options in the list(Combo box)Therefore promptting the user to
make a selection if the value is incorrect.
Thanks!
 
G

Graham Mandeno

Hi Angel

The NotInList event is only intended to deal with user input. However, it
should be easy for the code that is setting the value to check first that
the new value is valid.

For example, if the values come from a table, you can use DLookup to check
that the new value is in the table.

If this is too difficult for some reason, then you can always loop through
all the rows in your combo box to check:

Dim fValid as Boolean, i as Integer
With ComboBoxName
For i = 0 to .ListCount-1
If .ItemData(i) = NewValue then
fValid = True
Exit For
End If
Next
If fValid then .Value = NewValue
End With

Actually, this might be the most efficient way in any case, except if you
have more than a few hundred rows in your combo box.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top