Private Sub HorseNum_fk_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
Dim CR As String
CR = Chr$(13)
'Exit This subroutine if the combox box was cleared.
If NewData = "" Then Exit Sub
'Ask the user if he or she wishes to add a new horse.
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 New Horse form in data entry
'mode as a dialog form, passing the new horse name in
'NewData to the OpenForm method's OpenArgs argument. The
'Open Args argument is used in New Horse form's Form_Load event
'procedure.
DoCmd.OpenForm "frmHorse", , , , acAdd, acDialog, NewData
End If
'Look for the horse the user created in the New Horse form.
Result = DLookup("[HorseName]", "frmHorse", "[HorseName]='" & NewData & "'")
If IsNull(Result) Then
'If the horse 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 horse was created, set the Response argument to
'indicate that the new data is being added.
Response = acDataErrAdded
End If
End Sub