recordCount of Recordset returns 1, but is wrong

G

Guest

Hi all,

I'm hoping someone can help me because I've just about gone crazy. I'm
having issues with Recordset.recordCount

If I run a DCount on a query I get a value of 23.
Now, if I open a recordset on that same query (like so):
Set rst = CurrentDb.OpenRecordset("temp_qryGetQtyDCDO")

The rst.recordCount returns 1.

If I loop through each record in the recordset though, it goes through 23
records.
The only way I can get .recordCount to return 23 is to use rst.MoveLast.

Does anyone know what might be causing this? I use rst.recordCount in
another form and it works fine.

If you need more information, let me know.
Any and all suggestions are appreciated.

Thanks,
Jay
 
R

Rick Brandt

Jay said:
Hi all,

I'm hoping someone can help me because I've just about gone crazy. I'm
having issues with Recordset.recordCount

If I run a DCount on a query I get a value of 23.
Now, if I open a recordset on that same query (like so):
Set rst = CurrentDb.OpenRecordset("temp_qryGetQtyDCDO")

The rst.recordCount returns 1. [snip]

RecordCount is not accurate until you move to the last row. Issue a MoveLast
command and then check the count.
 
G

Guest

The recordcount property is not accurate until the recordset is fully
populated. The typical way to do that is:
Set rst = CurrentDb.OpenRecordset("temp_qryGetQtyDCDO")
If rst.RecordCount = 0 Then
MsgBox "The Recordset is Empty"
Else
rst.MoveLast
rst.MoveFirst
End If
lngCorrectCount = rst.RecordCount
'lngCorrectCount now contains the accurate record count for the record set
 
G

Guest

I had no idea about that...

Thanks to you both.

Klatuu said:
The recordcount property is not accurate until the recordset is fully
populated. The typical way to do that is:
Set rst = CurrentDb.OpenRecordset("temp_qryGetQtyDCDO")
If rst.RecordCount = 0 Then
MsgBox "The Recordset is Empty"
Else
rst.MoveLast
rst.MoveFirst
End If
lngCorrectCount = rst.RecordCount
'lngCorrectCount now contains the accurate record count for the record set
 

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

Top