0

I would like to verify if the value of a specific variable (oLookFullName) exist in this recordset and if it isn't the case I would like to print a message, so I tried this:

rs.MoveFirst

filter2 = "[Nom] = " & oLookFullName
rs.Find filter2
If (rs.BOF = True) Or (rs.EOF = True) Then
    Debug.Print oLookFullName & " is not find"
End If

But I have this error at the line rs.Find filter2:

Run-time error 3001 Arguments are of the wrong type or out of acceptable range or are in conflict with one another.
Nadhir
  • 528
  • 3
  • 12

1 Answers1

0

For DAO, try with:

filter2 = "[Nom] = '" & oLookFullName & "'"
rs.FindFirst filter2
If rs.NoMatch Then
    Debug.Print oLookFullName & " is not found."
End If

For ADO, try with:

filter2 = "[Nom] = '" & oLookFullName & "'"
rs.MoveFirst
rs.Find filter2
If rs.EOF Then
    Debug.Print oLookFullName & " is not found."
End If
Gustav
  • 53,498
  • 7
  • 29
  • 55
  • Vba compile error: Method or data member not found – Nadhir Aug 17 '21 at 14:12
  • I was writing it to you ... really sorry – Nadhir Aug 17 '21 at 14:19
  • Run-time error '-2147217879 (80040e29)': rowset does not support scrolling backward. On the line `rs.Find filter2` – Nadhir Aug 17 '21 at 15:57
  • You may have to first set the current row - [Find Method (ADO)](https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/find-method-ado?view=sql-server-ver15?WT.mc_id=M365-MVP-5002361). – Gustav Aug 17 '21 at 16:34
  • You need a different cursor type: https://stackoverflow.com/questions/14122308/rowset-does-not-support-scrolling-backward – Tim Williams Aug 17 '21 at 21:43
  • How can I add one more criteria in filter2 ? Because I have an error : filter2 = "[Nom] = '" & oLookFullName & "'" And "[nomEntreprise] = '" & objContact.CompanyName & "'" – Nadhir Aug 19 '21 at 14:39
  • 1
    You can't. You'll have to use some work-around for that. – Gustav Aug 19 '21 at 14:50