Combo box - error message

  • Thread starter Thread starter Patrick B via AccessMonster.com
  • Start date Start date
P

Patrick B via AccessMonster.com

I have a combo box - I want to display an error message when the item entered
is not in the list.
I created an msgbox macro to display the text that will display.
In the Combo box properties list, I placed the macro name in the "on Not in
list " option.
I can run the macro by itself and it displays ok. But when I enter an item
not in the combo box list, it gives me no error message.
What am I doing wrong.

Pat
 
You'll need to use code for this rather than a macro as you need to set the
return value of one of the NotInList event procedure's arguments. Put
something like this in the event procedure:

Dim ctrl As Control
Dim strMessage As String

Set ctrl = Me.ActiveControl

strMessage = NewData & "is not in the list."
MsgBox strMessage, vbExclamation, "Error"
ctrl.Undo
Response = acDataErrContinue
 
as well as following Ken's instructions for the VBA code, you have to set
the combo box's LimitToList property to Yes - or the NotInList event will
not run.

hth
 
Back
Top