I have an item lookup form that displays the information of a single record. There is an unbound combo box on the record that the user uses to type in the item number and go straight to that record via DoCmd.SearchForRecord. That part works fine.
What I would also like to do is have that unboundcombobox be able to add new items to the table. I have the NotInList right now set to this:
If MsgBox("Create new inventory item " & NewData & "?", _
vbQuestion + vbYesNo) = vbNo Then
Me.PartNumberList.Undo
Response = acDataErrContinue
Exit Sub
Else
CurrentDb.Execute "INSERT INTO Inventory ( PartNumber ) VALUES ('" & NewData & "');"
Response = acDataErrAdded
End If
The table receives the new data, but now I need to requery the form before the form can find the data. If I add Me.Requery immediately after that code, the form thinks I'm trying to enter the same item into the form, it still hasn't found it in the table, and it asks again if I want to add that item. If I try to requery the combobox first, it tells me I must save the data first. Adding If Me.Dirty then Me.Dirty = False right in front of the Requery doesn't fix this.
So after some searching I found that I should try moving to the first record in the combobox before a requery. This works except now I get an notice "The value you entered isn't valid for this field." I press OK and then everything is requeried and I can now manually navigate to my new part number. But I can't figure out exactly what is throwing this notice. On Error Resume Next doesn't bypass this notice. When I step through the code, the notice seems to happen after NotInList, and then it skips all other events. I won't fire my BeforeUpdate or AfterUpdate.
Maybe I'm just going about my item lookup all wrong. Maybe I should have the user add items with a different form. It would just be convenient to keep it all to one single form. Oh maybe it's worth mentioning, this form is opening as a Dialog, in the Add mode. But the errors stay the same even if I open the form by itself with Data Entry off.