I have a form with a combo box with all the Employee id's in it (cmbCDC). And on the form I have text boxes with the data for all the fields in the table ie: Name, ID, SSN, DOB, etc. When I input info in the cmbCDC that is not in the list I want a message box to pop up and ask if you want to add this data to the database. I can get the info into the database and everything works but I can't seem to get the cmbCDC to recognize that the new ID is in the combo box. When the form moves the focus to the name textbox I get the message "The text you entered isn't an item in the list." Here is the code and what am I doing wrong? I don't want the message to come up when the user already states that they want to add the information:
Private Sub cmbCDC_NotInList(NewData As String, Response As Integer)
Dim Temp As String
Dim Reply As String
Dim db As Database, rs As Recordset
Reply = MsgBox("Do you want to add this ID Number to the Database?", vbYesNo, "Confirm Add new record"
If Reply = vbYes Then
'This section uses DAO to add the record
Set db = CurrentDb
Set rs = db.OpenRecordset("Employees", dbOpenDynaset)
rs.AddNew
rs!CDC_Number = Me!cmbCDC.Text
Temp = Me!cmbCDC.Text
rs.Update
rs.Close
cmbCDC.SetFocus
Me!cmbCDC.Undo
Me!cmbCDC.Requery
Me.Requery
Me!cmbCDC.Text = Temp
MsgBox "Click on the Save Changes Button below when you are finished!", vbOKOnly, "Reminder to Save"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.GoToRecord , , acLast
'Me!txtCDC.SetFocus
'Me!txtCDC.Text = Temp
Me!txtName.SetFocus
Exit Sub
End If
End Sub
Thanks for all your help!
Rick
Private Sub cmbCDC_NotInList(NewData As String, Response As Integer)
Dim Temp As String
Dim Reply As String
Dim db As Database, rs As Recordset
Reply = MsgBox("Do you want to add this ID Number to the Database?", vbYesNo, "Confirm Add new record"
If Reply = vbYes Then
'This section uses DAO to add the record
Set db = CurrentDb
Set rs = db.OpenRecordset("Employees", dbOpenDynaset)
rs.AddNew
rs!CDC_Number = Me!cmbCDC.Text
Temp = Me!cmbCDC.Text
rs.Update
rs.Close
cmbCDC.SetFocus
Me!cmbCDC.Undo
Me!cmbCDC.Requery
Me.Requery
Me!cmbCDC.Text = Temp
MsgBox "Click on the Save Changes Button below when you are finished!", vbOKOnly, "Reminder to Save"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.GoToRecord , , acLast
'Me!txtCDC.SetFocus
'Me!txtCDC.Text = Temp
Me!txtName.SetFocus
Exit Sub
End If
End Sub
Thanks for all your help!
Rick