Conditional looping with ADO Recordset in VBA

pheeper

In the past, I've always generated reports by querying a database, dropping it on a worksheet, sorting, reading into an array, and then looping through to create the documents. What I'm trying to do now is generate the reports directly from the recordset.

The problem I have though is when using arrays I had an absolute record number, so I could check if a field in the previous record was the same as in the current record.

What is the best way of going about doing this with a recordset? Store the field value in a variable? Use nested While loops? Get a total record count and use absolute positions to move back and forth (which doesn't seem like a good idea)?

UPDATE The recordset contains multiple records from 20 different companies. I sort the query by the company name and then start loop through it. I then need to check each record to see if it's from the same company as the previous and if not create a new worksheet for that company.

thx1138v2

I usually do the sort in the query using an "Order By" clause. Then just loop through the sorted records using a variable to track the current sort order name and detect the name change by comparing the current record name field to the variable value.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related