Custom Msg Box requiring Selection from List

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

Guest

How do I force the user to select a value from the combo box using code? (I
know how to set Access properties) At what event should I include this code?
Also -- How do I replace the system message "must select from List" with my
own message? ---- Name.LimitToList = True --- ?

Thanks...
 
To force a choice, use the Exit event of the combo box:

Private Sub ComboBoxName_Exit(Cancel As Integer)
If Len(Me.ComboBoxName.Value & "") = 0 Then
Cancel = True
MsgBox "You must select an item from the list.", vbExclamation, _
"Make A Selection!"
End If
End Sub
 
It makes sense to write the code in the Exit event... however, I'm still
getting the system message instead of my own. (I am a novice!)
 
SharonInGa said:
How do I force the user to select a value from the combo box using code? (I
know how to set Access properties) At what event should I include this code?
Also -- How do I replace the system message "must select from List" with my
own message? ---- Name.LimitToList = True --- ?


Use the NotInList event procedure to run your own MsgBox.
Set the Response argument to suppress the standard message:

MsgBox "Select from the list"
Response = acDataErrContinue

An obscure alternative to the NotInList event is to use the
combo box's BeforeUpdate event to check if the entered data
is in the list and cancel the update if it's not:

If Me.thecombobox.ListIndex = -1 Then
MsgBox "Select from the list"
Cancel = True
End If

Neither of these techniques guarantees that the user won't
ignore the combo box so your tests may never execute.
 
Back
Top