{"id":12103,"date":"2024-02-03T02:59:33","date_gmt":"2024-02-03T02:59:33","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=973"},"modified":"2024-02-03T02:59:33","modified_gmt":"2024-02-03T02:59:33","slug":"record-count-property","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/","title":{"rendered":"ADO RecordCount Property – RecordSet Object"},"content":{"rendered":"
The RecordCount<\/strong> property returns a long value that indicates the number of records in a Recordset object<\/strong>. While establishing the connection to your Database, you can set the appropriate Cursor. The syntax is the same as shown in the below picture.<\/p>\n Where-<\/strong><\/p>\n
\nMany a times you might have observed that RecordCount <\/strong> Property does not return a correct number instead it always returns a number -1<\/strong>.
\nRecordCount<\/strong> Property returns -1<\/strong> because by default the Cursor is adOpenForwardOnly<\/strong>.
\nTo get the exact Record Count from your RecordSet Object, you need to select the Cursor as adOpenKeyset<\/strong> or adOpenStatic<\/strong><\/p>\nHow to Set Cursor while establishing the Connection:<\/h3>\n
Syntax:<\/h2>\n
rs.Open qry, conn, adOpenStatic<\/code><\/pre>\n
\n
\n rs:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong><\/td>\n Your Declared RecordSet<\/td>\n<\/tr>\n \n qry:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><\/td>\n Your SQL Query to be executed to get the Record Set<\/td>\n<\/tr>\n \n conn:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong><\/td>\n Opened Connection<\/td>\n<\/tr>\n \n adOpenStatic:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><\/td>\n Cursor Type<\/tr>\n<\/td>\n<\/table>\n