0

Hey I am using If InStr(1, rs.recordset1, rsx.recordset2) .. to find matching records. If there are more than 15 matches I want to exit the If condition. How can I count the records?

Code Example:

Do Until rs.EOF

If InStr(1, rs.Fields("Column1"), rs1.Fields("Column1")) > 0 Then

db.Execute "Insert into tbl_name (ColumnName) Values ( """ & rs.Fields("Column1") & """ ); ", dbFailOnError

End If

rs1.moveNext

Loop
Greedo
  • 4,967
  • 2
  • 30
  • 78
  • Use the recordset filter and count? Can you exmplain show what you mean fully, what you've tried – Nathan_Sav Apr 21 '21 at 11:27
  • 1
    Please provide the code that you are working on. We need that to see whether we can help you.... – Klaassiek Apr 21 '21 at 11:35
  • I would suggest using Regular Expressions. You can do something like `Regex.Global = True` (gets all matches) then `Regex.Pattern = rsx.recordset2` and `Set Matches = Regex.Execute(rs.recordset1)` and then access the number of matches using `Matches.Count` – Toddleson Apr 21 '21 at 14:18
  • Other than regex, you could also do `UBound(Split(rs.recordset1, rsx.recordset2))`. Add 1 to that number, and that is your number of matches. – Toddleson Apr 21 '21 at 14:25
  • Thanks for youre replies! My Code: Do Until rs.EOF if InStr(1, rs.Fields("Column1"), rs1.Fields("Column1")) > 0 Then db.Execute "Insert into tbl_name (ColumnName) Values ( """ & rs.Fields("Column1") & """ ); ", dbFailOnError End If rs1.moveNext Loop – user15717440 Apr 22 '21 at 09:11

0 Answers0