RecordSet Findfirst

Triscuit

Registered User.
Local time
Today, 06:24
Joined
Jul 20, 2010
Messages
27
I have an issue where my rstCalibrationInformation.NoMatch is not working. I would like to have a combo box where a user can pick a txtCalibGroup (PK) and a listbox will show a query related to the PK. That works fine, however I would like if the user entered a PK that doesn't match any of the records to add a new record with that PK. I think my code isn't entering the rstCalibrationInformation.NoMatch and creating a new record, because the list box is empty and no new record is created nor Msgbox.
Any suggestions?



Code:
Private Sub Search_Click()
'On Error GoTo Error_Search_Click:
   Dim db As DAO.Database
   Dim rstCalibrationGroup As DAO.Recordset
   
   Set db = CurrentDb
   Set rstCalibrationInformation = db.OpenRecordset("tblCalibrationInformation")
   
    If IsNull(Me!cboFilter) Then
        GoTo Finish
    End If

    rstCalibrationInformation.OpenRecordset.FindFirst " txtCalibGroup= '" & Me.cboFilter & "'"


    If rstCalibrationInformation.NoMatch Then
        rstCalibrationInformation.AddNew
        rstCalibrationInformation("txtCalibGroup").Value = Me!cboFilter
        rstCalibrationInformation.Update
        MsgBox "Added new entry"
    Else
        Me!LstSearch.RowSource = "SELECT txtLabNum FROM tblCalibrationGroup WHERE [txtCalibGroup] = '" & Me!cboFilter & "' "
    End If
       
    
Finish:
            Exit Sub
 
Exit_Search_Click:
    Exit Sub
 
'Error_Search_Click:
    'MsgBox Err.Number & Err.Description
   'Resume Exit_Search_Click

End Sub
 
Much better idea, thanks.
 

Users who are viewing this thread

Back
Top Bottom