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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Notinlist event on same form error

Status
Not open for further replies.

akasmia

MIS
Apr 12, 2002
30
US
Ok this is very simple BUT I am not making it work !.

I am using a single table underlying the same form which contains the combobox cmbFindbyLastName. When I enter new data in the combobox the message generated by the msgbox function keep hounding me !. Keeps saying the same thing "smith" not found do you want to add it?. When I finally give up and hit cancel then I get an error: Runtime error 3709; the search key was not found in any record.




HERE IS THE CODE:

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

    Dim ctl As Control
    Set ctl = Me.cmbFindbyLastName
    
    If MsgBox("This name: '" _
        & NewData & "' Does not exist do you want to add it to the list?", _
        vbOKCancel, "Add New Item?") = vbOK Then
        ' Undo combobox data just typed...
        ctl.Undo
        ' Add new record using the same form
        DoCmd.GoToRecord , , acNewRec
        ' Set forcus on the combo box
        Me.cmbFindbyLastName.SetFocus
        ' Store new name
        Me.cmbFindbyLastName.Text = NewData
        ' Requiry form ( update table)
        Me.Requery
        ' requiry combo box
        Me.cmbFindbyLastName.Requery
        ' Go to the last record ( newly added record)
        DoCmd.GoToRecord , , acLast
        ' Set focus on first name textb
        Me.First_Name.SetFocus
        ' Continue without displaying default error message.
        Response = acDataErrAdded
    Else
        Response = acDataErrContinue
    End If
        
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top