{"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>.
\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>\n

How to Set Cursor while establishing the Connection:<\/h3>\n

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

Syntax:<\/h2>\n
rs.Open qry, conn, adOpenStatic<\/code><\/pre>\n

Where-<\/strong><\/p>\n\n\n\n\n\n
rs:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong><\/td>\nYour Declared RecordSet<\/td>\n<\/tr>\n
qry:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><\/td>\nYour SQL Query to be executed to get the Record Set<\/td>\n<\/tr>\n
conn:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong><\/td>\nOpened Connection<\/td>\n<\/tr>\n
adOpenStatic:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><\/td>\nCursor Type<\/tr>\n<\/td>\n<\/table>\n
\"Connection<\/a>

Connection Syntax<\/p><\/div>\n

For Example: <\/strong>Below Code will give the Exact count of all records returned in your RecordSet Object.<\/p>\n

Sub Get_Count()\r\n\r\nDim conn As New Connection\r\nDim rs As New Recordset\r\n\r\n    strcon = \"Provider=Microsoft.ACE.OLEDB.12.0;\" & _\r\n    \"Data Source=E:\\Student.accdb;\" & _\r\n    \"User Id=admin;Password=\"\r\n\r\n    conn.Open (strcon)\r\n\r\n    qry = \"SELECT * FROM students\"\r\n    rs.Open qry, conn, adOpenStatic\r\n\r\n    MsgBox (rs.RecordCount)\r\n\r\n    rs.Close\r\n    conn.Close\r\n\r\nEnd Sub<\/code><\/pre>\n

Below are the Cursor Types and it’s description:<\/strong><\/p>\n\n\n\n\n\n\n\n\n
Cursor Type<\/span><\/th>\nDescription<\/span><\/th>\n<\/tr>\n
adOpenUnspecified<\/td>\nDoes not specify the type of cursor.<\/td>\n<\/tr>\n
adOpenForwardOnly<\/td>\nDefault. Uses a forward-only cursor. Identical to a static cursor, except that you can only scroll forward through records. This improves performance when you need to make only one pass through a Recordset.<\/td>\n<\/tr>\n
adOpenKeyset<\/td>\nUses a keyset cursor. Like a dynamic cursor, except that you can’t see records that other users add, although records that other users delete are inaccessible from your Recordset. Data changes by other users are still visible.<\/td>\n<\/tr>\n
adOpenDynamic<\/td>\nUses a dynamic cursor. Additions, changes, and deletions by other users are visible, and all types of movement through the Recordset are allowed, except for bookmarks, if the provider doesn’t support them.<\/td>\n<\/tr>\n
adOpenStatic<\/td>\nUses a static cursor. A static copy of a set of records that you can use to find data or generate reports. Additions, changes, or deletions by other users are not visible.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/span>","protected":false},"excerpt":{"rendered":"

The RecordCount property returns a long value that indicates the number of records in a Recordset object. Many a times you might have observed that RecordCount Property does not return a correct number instead it always returns a number -1. RecordCount Property returns -1 because by default the Cursor is adOpenForwardOnly. To get the exact […]<\/p>\n","protected":false},"author":45,"featured_media":975,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[5203,1246,1675],"tags":[],"class_list":["post-12103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database","category-macro","category-excel-macro-for-beginners"],"yoast_head":"\nADO RecordCount Property - RecordSet Object - Let's excel in Excel<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ADO RecordCount Property - RecordSet Object\" \/>\n<meta property=\"og:description\" content=\"The RecordCount property returns a long value that indicates the number of records in a Recordset object. Many a times you might have observed that RecordCount Property does not return a correct number instead it always returns a number -1. RecordCount Property returns -1 because by default the Cursor is adOpenForwardOnly. To get the exact […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/\" \/>\n<meta property=\"og:site_name\" content=\"Let's excel in Excel\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-03T02:59:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/vmlogger.com_-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vishwamitra Mishra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/learnexcelmacro\" \/>\n<meta name=\"twitter:site\" content=\"@learnexcelmacro\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishwamitra Mishra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"ADO RecordCount Property – RecordSet Object\",\"datePublished\":\"2024-02-03T02:59:33+00:00\",\"dateModified\":\"2024-02-03T02:59:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/\"},\"wordCount\":320,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#primaryimage\"},\"thumbnailUrl\":\"\",\"articleSection\":[\"Database\",\"Excel Macro\",\"Excel Macro Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/\",\"name\":\"ADO RecordCount Property - RecordSet Object - Let's excel in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#primaryimage\"},\"thumbnailUrl\":\"\",\"datePublished\":\"2024-02-03T02:59:33+00:00\",\"dateModified\":\"2024-02-03T02:59:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Database\",\"item\":\"https:\/\/vmlogger.com\/excel\/database\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"ADO RecordCount Property – RecordSet Object\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\",\"url\":\"https:\/\/vmlogger.com\/excel\/\",\"name\":\"Let's excel in Excel\",\"description\":\"Let's share knowledge\",\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vmlogger.com\/excel\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\",\"name\":\"Vishwamitra Mishra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"width\":528,\"height\":560,\"caption\":\"Vishwamitra Mishra\"},\"logo\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\"},\"description\":\"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.\",\"sameAs\":[\"http:\/\/www.learnexcelmacro.com\",\"http:\/\/www.facebook.com\/vmlogger\",\"https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro\",\"https:\/\/www.youtube.com\/c\/VMLogger\"],\"url\":\"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"ADO RecordCount Property - RecordSet Object - Let's excel in Excel","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/","og_locale":"en_US","og_type":"article","og_title":"ADO RecordCount Property - RecordSet Object","og_description":"The RecordCount property returns a long value that indicates the number of records in a Recordset object. Many a times you might have observed that RecordCount Property does not return a correct number instead it always returns a number -1. RecordCount Property returns -1 because by default the Cursor is adOpenForwardOnly. To get the exact […]","og_url":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/","og_site_name":"Let's excel in Excel","article_publisher":"http:\/\/www.facebook.com\/vmlogger","article_author":"http:\/\/www.facebook.com\/vmlogger","article_published_time":"2024-02-03T02:59:33+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/vmlogger.com_-1.png","type":"image\/png"}],"author":"Vishwamitra Mishra","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/learnexcelmacro","twitter_site":"@learnexcelmacro","twitter_misc":{"Written by":"Vishwamitra Mishra","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"ADO RecordCount Property – RecordSet Object","datePublished":"2024-02-03T02:59:33+00:00","dateModified":"2024-02-03T02:59:33+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/"},"wordCount":320,"commentCount":0,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#primaryimage"},"thumbnailUrl":"","articleSection":["Database","Excel Macro","Excel Macro Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/","url":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/","name":"ADO RecordCount Property - RecordSet Object - Let's excel in Excel","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#primaryimage"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#primaryimage"},"thumbnailUrl":"","datePublished":"2024-02-03T02:59:33+00:00","dateModified":"2024-02-03T02:59:33+00:00","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2024\/02\/record-count-property\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"Database","item":"https:\/\/vmlogger.com\/excel\/database\/"},{"@type":"ListItem","position":3,"name":"ADO RecordCount Property – RecordSet Object"}]},{"@type":"WebSite","@id":"https:\/\/vmlogger.com\/excel\/#website","url":"https:\/\/vmlogger.com\/excel\/","name":"Let's excel in Excel","description":"Let's share knowledge","publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vmlogger.com\/excel\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5","name":"Vishwamitra Mishra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","width":528,"height":560,"caption":"Vishwamitra Mishra"},"logo":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/"},"description":"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.","sameAs":["http:\/\/www.learnexcelmacro.com","http:\/\/www.facebook.com\/vmlogger","https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro","https:\/\/www.youtube.com\/c\/VMLogger"],"url":"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/"}]}},"_links":{"self":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12103"}],"collection":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/comments?post=12103"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12103\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=12103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=12103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=12103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}