OnNotInList event

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

The answer to this question may be obvious, but...

I have a field in a form that is a Combobox. If someone
types into the field a value that is not in the list, I
want to warn the user, blank the field to remove their
entry, then allow them to enter another value. Currently I
have the limit to list property set to yes. This does two
things I find undesirable: 1) an ugly message pops up
which is not all that user friendly and 2) it does not
clear the field, etc.

I am looking at using the OnNotInList event.

My question is, do I need to leave LimitToList set to yes?
If so, how do I suppress the Access message that pops up
and allow only my custom message to appear? I don't want
to allow them to enter something that is not in the list.

Thanks in advance!

Kevin
 
My question is, do I need to leave LimitToList set to yes?

-- Yes, you do. If you don't, then MS Access will not
fire the NotInList event.

If so, how do I suppress the Access message that pops up
and allow only my custom message to appear? I don't want
to allow them to enter something that is not in the list.

-- Clear the entry and then set Response =
acDataErrContinue (Response is an argument of the NIL
event). This will inform MS Access that you have provided
your user with a custom error message.

David Atkins, MCP
 
The Combo Box has a NotInList event.
Leave the LimitToList property to Yes.
Code the NotInList event:

MsgBox "You entered an item that is not in the list."
Response = acDataErrContinue
[ComboBoxName] = Null

You could also use this event to add an item to the list.
That's a another post, though, and it would depend on if
you added just the one item or needed to open a form to
add additional fields, i.e. open a Customer form to add information
about a Customer, not just the Customer's name.
 
Fredg said:
The Combo Box has a NotInList event.
Leave the LimitToList property to Yes.
Code the NotInList event:

MsgBox "You entered an item that is not in the list."
Response = acDataErrContinue
[ComboBoxName] = Null

Thanks.

Now for another related problem. In my application, setting th
combobox value to "Null" produces another problem. That value i
destined, by way of a query, for a field in a table (in this case
detail table) in which that field is part of a multi-part primar
key. And, as you know, a primary key field cannot contain a Null.

Is there a way to invalidate the entry at this point? To drop th
last entry and leave the combobox with valid entries above, and
blank drop-down box at the end awaiting a valid entry?

My combobox is on a subform. From it one may select none, one o
several from a list of attributes. The primary keys from two tables
one for Case and one for Attributes, comprise the two fields of th
detail table where the problem occurs when the subform's combobo
attempts to pass the Null value by way of the query.

Thanks.

Ji
 
Back
Top