I have a combobox in a form that looks up records based on this form itself(cyclist tbl).I also add new records to this same form if i cant find the IDNo of a person in this combobox. If i type in the IdNo of a person in the combobox and dont find it, then i want to move straight to the IDNumber field (first field on the form) called IdNo with the "on not in list" and create a new record to start entering immediately.
Combo is called = Combo177
Form = cyclistf
Table = cyclist
fields:
IdNo = primary key + txt
Surname = txt
Name = txt
Gender = txt
This code ask the right questions, but dont copy this IdNo that it cant find into a new blank field for me. If i say no, then it gets into a loop and you can't get out until you say yes it must add it, which it does not do properly. I need to refresh the data somehow i think.
pls help!!
Combo is called = Combo177
Form = cyclistf
Table = cyclist
fields:
IdNo = primary key + txt
Surname = txt
Name = txt
Gender = txt
This code ask the right questions, but dont copy this IdNo that it cant find into a new blank field for me. If i say no, then it gets into a loop and you can't get out until you say yes it must add it, which it does not do properly. I need to refresh the data somehow i think.
pls help!!
Code:
Private Sub Combo177_NotInList(NewData As String, Response As Integer)
On Error GoTo Combo177_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The Id number " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Entries")
If intAnswer = vbYes Then
strSQL = "INSERT INTO Cyclist([IdNo]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new Id number has been added to the list." _
, vbInformation, "Entries"
Response = acDataErrAdded
Else
MsgBox "Please choose an Id Number from the list." _
, vbInformation, "Entries"
Response = acDataErrContinue
DoCmd.GoToRecord , "", acNewRec
End If
Combo177_NotInList_Exit:
Exit Sub
Combo177_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume Combo177_NotInList_Exit
End Sub
Comment