Can I prevent user from typing 'wrong' text into combo box?

G

Guest

I have a combo box on a form that is limited to a predefined list of options.
If a user types in something not in the list then he will get an error
message as soon as he exits the control. However, I would prefer it if I
could prevent such an error from ever occurring, i.e. I want to prevent the
user from typing in anything that does not match all or part of an existing
list entry.

For example, if the list was Cat, Dog, Hamster, I would want the combo box
to accept a first character of c, d or h but to ignore the typing of any
other character.

Is there any easy way to achieve this? Note that the combo box is bound to a
hidden numeric key field.

David
 
D

Douglas J. Steele

I suppose you could put code in the combo box's KeyDown event to check, but
why?

If your problem is that they're putting a letter into the box and then
moving on, set the combo box's LimitToList property to True.
 
G

Guest

Hi Douglas,
The LimitToList property is already set to true (otherwise the user would
never trigger the error message I mentioned).

This is certainly a very minor issue. The standard Access behaviour of
triggering a "Not in List" error message when the user enters some
inappropriate text is perfectly acceptable. I just thought it might be very
slightly slicker to try and prevent such errors occurring in the first place
and wanted to be certain I was not missing some simple property setting that
would achieve this.

In the absence of such a property setting, I will have a look at creating
some suitable code for the combo box KeyDown or KeyPress event.

Thanks,
David
 
D

Douglas J. Steele

If LimitToList is True, you can put code in the combo box's NotInList event.
You can display your own message should you want, or choose not to display
anything. In either case, set

Response = acDataErrContinue

in the procedure.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


David Anderson said:
Hi Douglas,
The LimitToList property is already set to true (otherwise the user would
never trigger the error message I mentioned).

This is certainly a very minor issue. The standard Access behaviour of
triggering a "Not in List" error message when the user enters some
inappropriate text is perfectly acceptable. I just thought it might be
very
slightly slicker to try and prevent such errors occurring in the first
place
and wanted to be certain I was not missing some simple property setting
that
would achieve this.

In the absence of such a property setting, I will have a look at creating
some suitable code for the combo box KeyDown or KeyPress event.

Thanks,
David
 
G

Guest

Douglas,
Thanks for that interesting idea (I'd forgotten about the NotInList event).
That gives me another useful option in my attempt to handle 'wrong' input in
the slickest manner.

David
 
G

Guest

Douglas,
Thanks for that interesting idea (I'd forgotten about the NotInList event).
That gives me another useful option in my attempt to handle 'wrong' input in
the slickest manner.

David



Douglas J. Steele said:
If LimitToList is True, you can put code in the combo box's NotInList event.
You can display your own message should you want, or choose not to display
anything. In either case, set

Response = acDataErrContinue

in the procedure.
 

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