Counting rows in a datasheet

diggorydoo

New member
Local time
Today, 19:22
Joined
Mar 16, 2007
Messages
1
I have a datasheet based on a query and wish to count the number of rows in the datasheet. There is no single unique key in the datasheet, the unique number comes from a combination of two fields. How do I get the datasheet to return the total amount of rows?

Please help!
 
Simplest way is to look in the bottom left corner of the datasheet ( row x of z )
 
No reason RecordCount won't work. Just force a MoveLast/MoveFirst before the RecordCount to force the entire recordset into memory.

Me.Recordset.MoveLast
Me.Recordset.MoveFirst
NumRecords = Me.Recordset.RecordCount

You may want to check for EOF prior to performing the above to make sure the recordset isn't empty.

If you'd rather not code it like that, you can use a DCount on one of your two primary key fields, assuming you have your keys setup to not allow NULLs.

NumRecords = DCount("YourPrimaryKeyFieldName","YourTableName")

The first method will return the number of records regardless of whether or not there are NULLs in your data. The second method assumes no NULLs and will give an inaccurate count if NULLs exist on the field being counted.
 

Users who are viewing this thread

Back
Top Bottom