Private Sub NeighID_NotInList(NewData As String, Response As Integer)
'Used from Microsoft's Support pages (Q197526)
Dim Result
Dim Msg As String
Dim CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Ask the user if he or she wishes to add the new neighborhood.
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Neighborhood Information form in data entry
' mode as a dialog form, passing the new Neighborhood name in
' NewData to the OpenForm method's OpenArgs argument. The
' OpenArgs argument is used in the [Neighborhood Information] form's Form_Load
' event procedure.
DoCmd.OpenForm "Neighborhood Information", , , , acAdd, acDialog, NewData
End If
' Look for the neighborhood the user created in the Customers form.
Result = DLookup("[NeighName]", "tableNeighborhoods", "[NeighName]='" & NewData & "'")
If IsNull(Result) Then
' If the neighborhood was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the neighborhood was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End Sub