Why .RecordCount() not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am confused as to why .RecordCount() won't return the expected value in the
following code

Dim dbDatabase1 As Database
Dim qryQueryDef1 As QueryDef
Dim rstID1 As Recordset
Set dbDatabase1 = CurrentDb()
Set qryQueryDef1 = dbDatabase1.QueryDefs("qry_letter")
qryQueryDef1("Enter the ID number") = Form_frm_letter.com_person
Set rstID1 = qryQueryDef1.OpenRecordset()

rstID1.RecordCount() always returns the value 1 even when there are more
records in the recordset. In addition the rstID1.MoveFirst and
rstID1.MoveNext methods work fine.

rstID1.RecordCount() will work if rstID1 is the recordset for a form.

Can anyone explain this to me please?
Anna
 
RecordCount will return the number of records that the recordset has
accessed so far. When the recordset is first loaded, it loads just the first
record...therefore, the value of RecordCount is 1. If there are no records,
the value is 0.

Sometimes, the RecordCount will show a value of -1 if there are records but
none have been accessed yet.

So, the way to get the actual count is to do a MoveLast method on the
recordset and then get the RecordCount. Be sure to do a MoveFirst afterwards
so that you start at the beginning of the recordset.
 
Back
Top