Jun 19, 2002 #1 softlover Programmer Joined Apr 4, 2002 Messages 88 Location CN Any one help me to count the total row number of a table?
Jun 20, 2002 #2 oharab Programmer Joined May 21, 2002 Messages 2,152 Location GB 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 ---------------------------------- Upvote 0 Downvote
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 ----------------------------------
Jun 20, 2002 #3 scking Programmer Joined Jan 8, 2001 Messages 1,263 Location US 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 Upvote 0 Downvote
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
Jun 20, 2002 #4 oharab Programmer Joined May 21, 2002 Messages 2,152 Location GB 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 ---------------------------------- Upvote 0 Downvote
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 ----------------------------------
Jun 20, 2002 #5 scking Programmer Joined Jan 8, 2001 Messages 1,263 Location US 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 Upvote 0 Downvote
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