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