user1818042
user1818042

Reputation: 73

how to filter from ADODB.Recordset in vba

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?

Upvotes: 0

Views: 7882

Answers (2)

Ara Proshyan
Ara Proshyan

Reputation: 1

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

rsContacts.Filter=""

or

rsContacts.Filter=adFilterNone

Upvotes: 0

Storax
Storax

Reputation: 12207

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

Upvotes: 1

Related Questions