devxlogo

Filtering Recordset Data

Filtering Recordset Data

Question:
After retrieving data into a recordset object, I want to filter this data. I tried using the objRs.filter method of ADO, but it doesn’t seem to work.

This is my syntax:

objRSEmp.Filter = "EmpName like 'b*'"

EmpName is the name of the field in my SQL table.

I tried using a session variable, but after that I can’t use any of the recordset’s properties through the new variable. Can you help?

Answer:
Just setting the Filter property doesn’t do it. You then have to set the recordset object to itself or another variable, like so:

objRSEmp.Filter = "EmpName like 'b*'"Set objRSFiltered = objRSEmp

Depending on how big the recordset is, you may want to just do another query from the database. It will probably run faster, especially if you create a stored procedure to do the work for you. Also, make sure you have indexes on the fields that you are using in your filters.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist