I added the NotInList code to my Suppliers combobox on my main form. If the user types in an item not in the combo box, it throws up my custom message asking them if they want to add it. I choose yes, and it opens my Contacts form in data entry mode. I add info for the new supplier, close the form, and I am returned to my main form with focus on the Supplier combobox. The problem is that it won't populate it with my new data. The newly added Supplier is in the list when I click the drop down arrow, but it won't let me select it. I have tried this a few times, added a couple new suppliers, and it still won't let me choose any of them.
Code is as follows:
and I have code in the f_Contacts form Load event:
I have used this code before in other combo boxes and it works perfect. Does anyone have any ideas on what may have gone wrong with this one and how I can fix it?
Thanks!!!
~Molly
Code is as follows:
Code:
Private Sub cboSupplier_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
Dim CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Ask the user if he or she wishes to add the new Contact(Supplier).
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Contacts form in data entry
' mode as a dialog form, passing the new supplier name in
' NewData to the OpenForm method's OpenArgs argument. The
' OpenArgs argument is used in Contact form's Form_Load event
' procedure.
DoCmd.OpenForm "f_Contacts", , , , acAdd, acDialog, NewData
End If
' Look for the supplier the user created in the Contacts form.
Result = DLookup("[EntityName]", "tblContacts", _
"[EntityName]='" & NewData & "'")
If IsNull(Result) Then
' If the supplier contact was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the supplier contact was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End Sub
and I have code in the f_Contacts form Load event:
Code:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
' If form's OpenArgs property has a value, assign the contents
' of OpenArgs to the EntityName field. OpenArgs will contain
' an entity name if this form is opened using the OpenForm
' method with an OpenArgs argument, as done in the Orders
' form's DonationContacts_NotInList event procedure.
Me![EntityName] = Me.OpenArgs
End If
End Sub
I have used this code before in other combo boxes and it works perfect. Does anyone have any ideas on what may have gone wrong with this one and how I can fix it?
Thanks!!!
~Molly