loop through recordset

gpass

New member
Local time
Today, 13:37
Joined
Jun 30, 2006
Messages
9
What's the preferred way to loop through a recordset to get the record count? All this move next, do until, EOF etc. get's confusing.
Your thoughts is greatly appreciated.
 
What is it that you are getting confused with? I have always used the following code to loop through a rs and get a count...important thing is to make sure you .Movefirst if you need to use the rs again for anything else.

Dim intNumRecs as Integer
intNumRecs = 0

Do Until rsMonthlyConf.EOF
rsMonthlyConf.MoveNext
intNumRecs = intNumRecs + 1
Loop

rsMonthlyConf.MoveFirst
 
Code:
if rst.eof then 
[INDENT]' EOF = end of file - there are no records
msgbox "No records"[/INDENT]
exit sub

rst.movelast
[INDENT]' without .movelast your record count will be one
' once you've moved to the end you'll
' know how many records there are[/INDENT]
msgbox rst.recordcount
 
This may be stupid, but what's wrong with the .RecordCount property? Open your recordset, check for EOF, if it's not EOF, do a MoveLast (which forces the entire recordset to load) and then it's just RecCount = rs.RecordCount.

psuedo-code

Code:
rs.open
If not rs.EOF Then
    rs.MoveLast
    RecCount = rs.RecordCount
    rs.MoveFirst
Else
    RecCount = 0
End If
 
I dont think there is anything stupid about that at all Moniker, looks like a good way to do it to me.
 
I Agree with Selevanm I'd do it more like this though

If not rs.EOF Then
rs.MoveLast
rs.MoveFirst
End If
RecCount = rs.RecordCount
 

Users who are viewing this thread

Back
Top Bottom