I have a form that has a combo box and if the user types in a value that is not in the list I have a message box pop up to ask if the user wants to add the value. If the user wants to add the value, the value is added to the database and then the value is placed into a text box. I can get the new value into the database but I run into a problem getting the new value into the combo box so that I can move on without the Message popping up "The text you entered isn't an item in the list". I can add the item to the database but when I requery the combobox I get this message:
Run-Time error "2118":
You must save the current field before you run the Requery action.
Here is the code:
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 Item Number to the Database?", vbYesNo, "Confirm Add new record"
If Reply = vbYes Then
Set db = CurrentDb
Set rs = db.OpenRecordset("Products", dbOpenDynaset)
rs.AddNew
rs!Item_Number = Me!cmbCDC.Text
Temp = Me!cmbCDC.Text
rs.Update
rs.Close
Me!cmbCDC.Requery
Me!txtCDC.SetFocus
Me!TxtCDC.Text= Me!cmbCDC.Text
Exit Sub
End If
Any ideas on what I am doing wrong?
Thanks in advance!
Rick
Run-Time error "2118":
You must save the current field before you run the Requery action.
Here is the code:
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 Item Number to the Database?", vbYesNo, "Confirm Add new record"
If Reply = vbYes Then
Set db = CurrentDb
Set rs = db.OpenRecordset("Products", dbOpenDynaset)
rs.AddNew
rs!Item_Number = Me!cmbCDC.Text
Temp = Me!cmbCDC.Text
rs.Update
rs.Close
Me!cmbCDC.Requery
Me!txtCDC.SetFocus
Me!TxtCDC.Text= Me!cmbCDC.Text
Exit Sub
End If
Any ideas on what I am doing wrong?
Thanks in advance!
Rick