Bobski Bobski - 8 months ago 31 Question

For Next loops continues every if at limit

I'm working on an application and for some reason I have an issue understanding something. I have code that looks like this....

dim number as integer

number = rs.recordcount (only 1 record - so number = 1)
for x = 1 to Number

I'm assuming that once it gets to rs.movenext and then goes onto to Next, it should simply exit the loop - yet it seems to go back to the top of the loop even though there is no record. Anyone have any idea why that's happening?


RecordCount returns the number of records that have been read, or something like that - it does not return the total number of records, that value isn't known until the recordset has been iterated.

So a For...Next loop can't iterate a recordset efficiently.

Try a While loop instead:

While Not rs.BOF And Not rs.EOF