If, by "For loop" you mean a "For Each" loop, then you are out of louck. A
recordset does not expose its Records collection (which is not really a
collection - note: there is no "Records" property in a Recordset object) via
the IEnumerable interface, so "For Each" cannot be used to loop through the
records of a recordset the way it can be used to loop through its Fields
collection:
for each fld in rs.Fields
response.write fld.Name & ": " & fld.Value & "<BR>"
next
If you are talking about a "For i=0 to something" loop, then you need to use
a cursortype that supports bookmarks. This is because you need a way to
1. Tell the recordset which record to point to, and
2. Tell the loop to stop at the last record, using the recordcount (which is
only available with static, keyset and dynamic cursors)
Anyways, if you set the cursortype to either 1(keyset), 2(dynamic) or 3
(static), or set the cursorlocation to 3 (adUseClient), guaranteeing that
you will get a static cursor, before you open the recordset, you will
receive a bookmarkable cursor which will allow you to do this:
rows=rs.RecordCount
if rows > 0 then
for i = 1 to rows
rs.AbsolutePosition=i
'do stuff with current record
next
end if
Such cursortypes are more expensive (consume more system resources) than the
default forwardonly cursor. If you are going to loop through a recordset,
then use the simple "Do While Not rs.EOF...Loop" or "Do Until rs.EOF
....Loop" loops - they will be much more efficient. Better yet, use GetRows
or GetString where appropriate.
HTH,
Bob Barrows