Record count wrong

John thomas

Registered User.
Local time
Yesterday, 18:11
Joined
Sep 4, 2012
Messages
206
Hi
im New to record sets
and have copied this code as a test

Option Explicit

Public Sub LoadArray()
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("chimneysweep")

With rs
Debug.Print .RecordCount
.Close

End With

Set rs = Nothing
Set db = Nothing


In my immediate windoww it shows 1 record there are in fact 321 what am i doing wrong
I have tried different table still it only returns 1 record
many thanks john
 
You have to do
.Movelast

before you get an accurate recordcount.

Code:
Option Explicit

Public Sub LoadArray()
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("chimneysweep")

With rs
[COLOR="Blue"].movelast[/COLOR]
Debug.Print .RecordCount
.Close

End With

Set rs = Nothing
Set db = Nothing
 
A recordset does not necessarily fully populate itself after opening. Common practice to count all the records would be to move the current record pointer to the last record using the recordset's .MoveLast method. Consider the follow code fragment...
Code:
with currentdb.openrecordset("someTable")
   if not .eof then .movelast
   msgbox .recordcount
   .close
end with
hth :)
 

Users who are viewing this thread

Back
Top Bottom