So here are the steps you need to take after the new record is saved:
* Requery the combo box
* Set Focus to the combo box
* Set the Text property of the combo box to the Name of the customer, not the ID. Name being the type of value that's normally display after selecting a value in the combo. Notice I said Text property, not Value.
Private Sub CustomerID_NotInList(NewData As String, Response As Integer)
DoCmd.OpenForm "entercustomer", , , , , acDialog, NewData
CustomerID.Undo
CustomerID.Requery
CustomerID = DLookup("ID", "tblCustomers", "ID=" & NewData)
End Sub
Btw...when I look at my code compared to the code you used in the event procedure for 'not in list,' the only difference I see is that you put an apostrophe in front of each line of code including the line in between the lines of code.
It made the text green, which means it's a comment. So, doesn't that mean there's actually no code being run there??
Because you weren't using the NotInList event properly.Bob...
YOU ARE THE MAN! LOL thanks for your help...just like that it's fixed. Just awesome...
1) Why was I getting an error code in the 1st place?
First off, with Access 2007/2010 you don't need NotInList code at all. You just use the List Items Edit Form property of the combo box to specify a form to use to add the new data.2) What code did you change? Where was I going wrong?
If you look at the On Load event of the form to add the information I used the Split function to do it.3) Very cool on getting the 1st name to prefill in to the 1st name field and the last name to prefill into the last name field.
Because you weren't using the NotInList event properly.
First off, with Access 2007/2010 you don't need NotInList code at all. You just use the List Items Edit Form property of the combo box to specify a form to use to add the new data.
If you look at the On Load event of the form to add the information I used the Split function to do it.
Private Sub Form_Load()
If CurrentProject.AllForms("Form10").IsLoaded Then
Dim varSplit As Variant
varSplit = Split(Forms!Form10!CustomerID.Text, " ")
Me!FirstName = varSplit(0)
Me!LastName = varSplit(1)
End If
End Sub