Notln List Control

The NotInList event is triggered if the user enters a value that is not in the list when the LimitToList property of a combo box control is set to True. The NotInList event procedure can take the following two arguments:

NewData — A string that Access uses for passing to the event procedure the text that the user entered.

Response — An integer specifying what Access should do after the procedure executes. This argument can be set to one of the following constants: acDataErrAdded — Set the Response argument to acDataErrAdded if the event procedure enters a new value in the combo box. This constant tells Access to requery the combo box, adding the new value to the list. acDataErrDisplay — Set the Response argument to acDataErrDisplay if you want Access to display the default error message when a user attempts to add a new value to the combo box. The default Access message requires the user to enter a valid value from the list. acDataErrContinue — Set the Response argument to acDataErr-Continue if you display your own message in the event procedure. Access will forego displaying its default error message.

The NotInList event applies only to combo boxes. Use this event to display a custom warning message or trigger a custom function that allows the user to add a new item to the list.

For example, after attempting to enter a nonexisting value in the combo box labeled Room Type in the Room Information section of the Asset Management sample form, the following event procedure is executed:

Private Sub cboRoomType_NotInList(NewData As String, _

Response As Integer) MsgBox "Please select a value from the list.", _ vbInformation + vbOKOnly, "Invalid entry" ' Continue without displaying default error message. Response = acDataErrContinue End Sub

The code above displays a custom message if a user attempts to type an invalid entry in the cboRoomType combo box control on the form.

Part IV

0 0

Post a comment