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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

query on query 1
can't find strSQL 1
EXCEL VBA - recordcount = -1 0
.recordcount is always doubled 27
Case Select problem 3
Access Access Table Array 1
DAO Recordset Issue 1
RecordCount problem 2

Back
Top