Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Finder does not find record after Not In List procedure

Status
Not open for further replies.

TrekBiker

Technical User
Nov 26, 2010
330
GB
My Combo10 correctly finds records it its form.

This NotInList event correctly adds any new Customer entered in the combo.

Code:
Private Sub Combo10_NotInList(NewData As String, Response As Integer)

    Dim strSQL As String
    Dim i As Integer
    Dim Msg As String

    'Exit this sub if the combo box is cleared
    If NewData = "" Then Exit Sub

    Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
    Msg = Msg & "Do you want to add it?"

    i = MsgBox(Msg, vbQuestion + vbYesNo, "New customer...")
        If i = vbYes Then
          strSQL = "Insert Into Customers ([Customer]) values ('" & NewData & "')"
                CurrentDb.Execute strSQL, dbFailOnError
                Response = acDataErrAdded
            Else
                Response = acDataErrContinue
        End If

End Sub

When I select the new Customer from the combo's drop-down list the form doesn't update and open a new record for this Customer, but stays where it was before the NotInList fired.

This is the combo's AfterUpdate, where I've tried forcing a save and turning any filter off. They don't resolve the problem, but closing and reopening the form does.

Code:
Private Sub Combo10_AfterUpdate()
On Error GoTo Combo10_AfterUpdate_Err

    If Me.Dirty Then Me.Dirty = False
    Me.FilterOn = False
    
    DoCmd.SearchForRecord , "", acFirst, "[CustomerID] = " & Str(Nz(Screen.ActiveControl, 0))
    Me.Combo10 = Null
    
Combo10_AfterUpdate_Exit:
    Exit Sub

Combo10_AfterUpdate_Err:
    MsgBox Error$
    Resume Combo10_AfterUpdate_Exit

End Sub
 
Are you requerying the recordset driving the combo box and form after you add the new customer to the table? If your combo box "Limit to List" field is set to false (which it usually is by default) the it will let you put whatever you want in there even if it isn't necessarily in the dataset for the combo box yet. I.e. your combo box might let you put the new customer name in there even though it doesn't recognize that it's within it's own dataset, but that would cause the rest of your updating to fail.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top