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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the total row number of a table?

Status
Not open for further replies.

softlover

Programmer
Apr 4, 2002
88
CN
Any one help me to count the total row number of a table?
 
Try this function:

Function CountRows(strTableName As String) As Integer
Dim db As DAO.Database
Dim rst As DAO.Recordset

On Error Resume Next

Set db = CurrentDb
Set rst = db.OpenRecordset(strTableName)

rst.MoveLast
CountRows = rst.RecordCount

rst.Close
db.Close

Set rst = Nothing
Set db = Nothing

End Function

HTH

Ben ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
Yes but an alternative is simpler, depending on what you need it for. The following samples were run in the immediate window and pasted here.

?DCount("*", "tblComponent")
17744

If you use the field name of the primary key in DCount it will also return the count.

?DCount("[CP/N]", "tblComponent")
17744

Steve King

Growth follows a healthy professional curiosity
 
oh yeah! didn't think of that one!
Funny how using one thing all day blinkers you.

B ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
Ben,

Your solution was the one I use 95% of the time but I always look for the easiest way to do things. Does that make me lazy?

Steve Growth follows a healthy professional curiosity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top