0

I am using ADODB.Recordset in my vba program, loading all record from table to recordset and want to filter record inside the loop based on loop(i value).

I am using below code to filter record from recordset:

for (dim i as integer = 1 to 10)
    rsContacts.Filter = "Name = '" & Cell(i,1) & "' and Id = '" & Cell(i,2)& "'"
next

It's filtering properly returning one record when i = 1 but when i = 2 recordset doesn't have any record. How can filter record but want to keep full recordset so that it will filter properly?

2
  • Before anyone would be willing to read your question and try to help, please format it properly. Commented Dec 26, 2016 at 11:27
  • for (dim i as integer = 1 to 10) is a syntax error in VBA. Commented Dec 27, 2016 at 4:47

2 Answers 2

1

Maybe you need to add code to move to the first record. rsContacts.MoveFirst

Another suggestion would be to clear the filter beforehand rsContacts.Filter = adFilterNone

Sign up to request clarification or add additional context in comments.

Comments

0

Before the next step in the For - Next cycle, try clear filtering by

rsContacts.Filter=""

or

rsContacts.Filter=adFilterNone

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.