Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Created a Recordset, .RecordCount is one less than s/b 1

Status
Not open for further replies.

20dogdays

Programmer
Jun 13, 2007
10
US
Code/

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("ELUR1")
intNumbRows = rst.RecordCount
/Code
intNumbRows contains one less than the actual number of rows in the table. What am I doing wrong?
tia
 
I believe you need to move to the end of the record set before the recordcount can be relied upon.

rst.movelast
intNumbRows = rst.RecordCount
' then move to beginning to process forward
rst.movefirst
 
I tried that and got same result, my table has six rows and rst.RecordCount gives me 5. It misses the last record in the table. Access 2000
 
Light dawns on Marblehead, it seems the rst.RecordCount is zero based. Now works fine.

thx
 
What is the result of the following ?
MsgBox DCount("*", "ELUR1")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
There are six rows in the table ELUR1. Just after I created the recordset I inserted the MsgBox...., result was 6.
rst.RecordCount was still 5.
 
I stopped using the RecordCount property years ago because I couldn't keep track of the different ways you had to use it depending on database type, cursor type, cursor location, etc. If I need a count of records I simply do a:

SELECT COUNT(*) FROM Table

or similar, or DCount. I just find that pure SQL is 100% reliable as compared to some of the ADO properties.

 
By the way, I hope you're not opening an entire table just to get the record count! If that's the case, for sure use the alternative I posted!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top