Avatar of João serras-pereira
João serras-pereira
Flag for Portugal asked on

type mismatch on rst.findfirst

Hi -
On my app I need to validate it a certain record exists, before trying to insert a new one. The the existence is determined by a rst.findferst on the rst (a query), that combines two columns.

my code is:

    Dim tblSelecaoDetail_r As DAO.Recordset
    Dim qryMMRfilterNew_rst As DAO.Recordset
    Dim tblSelecaoDetail_rst As DAO.Recordset
    Dim qrySelecaoExistencias_rst As DAO.Recordset
   
    Dim strLocateSelected As String
    Dim lngNumRecords As Long
    Dim strX As String
   
    Set BddPlus = CurrentDb
    Set qryMMRfilterNew_rst = BddPlus.OpenRecordset("qryMMRfilterNew", dbOpenDynaset)
    Set tblSelecaoDetail_rst = BddPlus.OpenRecordset("tblSelecaoDetail", dbOpenDynaset)
    Set qrySelecaoExistencias_rst = BddPlus.OpenRecordset("qrySelecaoExistencias", dbOpenDynaset)

...

   Do While Not qryMMRfilterNew_rst.EOF
        ' acrescentar os registos seleccionados de qryMMRfilterNew à selecção escolhida
        ' mas... se já existe... não inserir!
        strLocateSelected = "existe = '" & Me.frmfld_refSelecao & qryMMRfilterNew_rst!CodMilitante & "'"
        qrySelecaoExistencias_rst.FindFirst strLocateSelected
        If qrySelecaoExistencias_rst.NoMatch = "" Then
            tblSelecaoDetail_rst.AddNew
            tblSelecaoDetail_rst!CodMilitante = qryMMRfilterNew_rst!CodMilitante
            tblSelecaoDetail_rst!refSelecaoMaster = Me.frmfld_refSelecao
            tblSelecaoDetail_rst.Update
            lngNumRecords = lngNumRecords + 1
        End If
        qryMMRfilterNew_rst.MoveNext
    Loop

but I am getting, on the  rst.nomatch statement tye "type mismatch" error

the rst looks OK as well as the search field...

Screen-Shot-2017-10-27-at-11.47.11.png
Screen-Shot-2017-10-27-at-11.47.19.png
can anyone help?
Microsoft AccessVBA

Avatar of undefined
Last Comment
João serras-pereira

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jim Dettman (EE MVE)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
João serras-pereira

ASKER
Thanks!!
now I am posting a related quesiton as it is always returning TRUE but the record is there so it should return FALSE...
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck