J
jv
I have a combo box that lists all of my applicant's last
names. I am able to enter a name in the combo box and if
it is not there...a message box pops up and asks if I
would like to add it. However, I don't know the code to
add a new record and and place this name I put in the
combo box as the new last name....Any help is
apreciated...Here is my code:
Private Sub Combo56_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 combo box was
cleared.
If NewData = "" Then Exit Sub
' Ask the user if he or she wishes to add the
new customer.
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 Customers
form in data entry
' mode as a dialog form, passing the new
company name in
' NewData to the OpenForm method's OpenArgs
argument. The
' OpenArgs argument is used in Customer
form's Form_Load event
' procedure.
DoCmd.OpenForm "Applicant", , , , acAdd,
acDialog, NewData
End If
' Look for the customer the user created in the
Customers form.
Result = DLookup("[Applicant1 Last
Name]", "tblApplicant", _
"[Applicant1 Last Name]='" & NewData
& "'")
If IsNull(Result) Then
' If the customer 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 customer was created, set the
Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End Sub
names. I am able to enter a name in the combo box and if
it is not there...a message box pops up and asks if I
would like to add it. However, I don't know the code to
add a new record and and place this name I put in the
combo box as the new last name....Any help is
apreciated...Here is my code:
Private Sub Combo56_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 combo box was
cleared.
If NewData = "" Then Exit Sub
' Ask the user if he or she wishes to add the
new customer.
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 Customers
form in data entry
' mode as a dialog form, passing the new
company name in
' NewData to the OpenForm method's OpenArgs
argument. The
' OpenArgs argument is used in Customer
form's Form_Load event
' procedure.
DoCmd.OpenForm "Applicant", , , , acAdd,
acDialog, NewData
End If
' Look for the customer the user created in the
Customers form.
Result = DLookup("[Applicant1 Last
Name]", "tblApplicant", _
"[Applicant1 Last Name]='" & NewData
& "'")
If IsNull(Result) Then
' If the customer 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 customer was created, set the
Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End Sub