combobox question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am a new programmer with a question about comboboxes. My combo has the
Limit To List property set to Yes. When I enter a value not on the list, I
get the standard Access message, "The text you entered isn't an item... " .
I'm trying to trap this error so I can use my own custom message, but no luck
yet. How do I go about doing this?
 
Terry,

Use the event 'On Not In List' in the properties for the combobox.

Set your code there to manage the situation.


Regards

swas
 
hi swas
Your suggestion to use the On NotInList allowed me to add my own error
message, but then the standard system message followed. I tried to turn this
off with DoCmd.SetWarnings False, but no luck. Any ideas?
 
Terry,

There would be a few ways, depending on how you want your form to interact
with the user.

If you just want to limit to list, then the Access error is probably
suitable alone.

If you want to have your own error, then you would need to leave the
combobox in a state that is suitable for Access to then accept. Examples
would be add the new value to the combobox After validating any other info),
or set the combobox to a blank "", or restore the combo.oldvalue which is the
previous value it was set to (combo = combo.oldvalue). Setting combo.undo
should have the same effect as the latter.

Unfortunately I am not a programmer, so sorry if this sounds vague... but
happy to help whare I can.

swas
 
You need to decide what you want to do in that situation.

You might want to open another form (in dialog mode) to add
the item to the list, or, if the table is a simple list, add
the new value directly to the table, or you might want to
discard the offending value (Me.combo.Undo).

In all of those cases, you will want to set the NotInList
event procedure's Response argument to either
acDataErrorAdded or acDataErrorContinue.
 
Hi Terry
You can put your own script in the event not in list. However after that you
must place cancel=true to avoid the regular standard access message.
I do use the following script myself;
begin code:
Private Sub ComboName_NotInList(NewData As String, Response As Integer)
MsgBox "This value " & " ( " & NewData & " ) " & " is not within the
list." & vbCrLf & vbCrLf & _
"Select a name from the list" & vbCrLf & _
vbCrLf & _
"Choose an other search function", vbInformation, "ComboSearch"
Response = acDataErrContinue
Me.ComboName = Null
Cancel = True
end sub
end code
Good luck
Harry
 
Back
Top