Here's an idea... use a constant end of file record in the datapool then you can use:
do while ThisRecord<>EOFRecord
'the procedure/statement list goes here
... instead of a for...next loop. That way you don't need to know how many records there are. The trick to this is to fetch a row & check the value once before the loop statement (in case the datapool is empty) and then do this again as the last two statements within the loop - this works for me every time. If you actually need to know how many there are, you can increment a counter within the loop too...