VBA 中的记录集计数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21820663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Recordset count number in VBA
提问by Hyman.
Is there a way to get the number of rows of recordset without using the movelast method in VBA? If I try to use the movelast method, the function will stop as i am using the UDF.
有没有办法在不使用 VBA 中的 movelast 方法的情况下获取记录集的行数?如果我尝试使用 movelast 方法,该函数将在我使用 UDF 时停止。
回答by Tmdean
Yes, but you have to open the Recordset using adOpenStatic
. This will pull the entire Recordset into memory, so it's not a good idea if your application doesn't need to process the entire recordset, you need to view changes made by other users, or if it's too big to fit into memory.
是的,但您必须使用adOpenStatic
. 这会将整个 Recordset 拉入内存,因此如果您的应用程序不需要处理整个记录集,您需要查看其他用户所做的更改,或者它太大而无法放入内存,这不是一个好主意。
rs.Open "source", , adOpenStatic
Debug.Print rs.RecordCount
回答by BzKnt
Article here http://www.geeksengine.com/article/recordcount-ado-recordset-vba.htmlexplains the issue very clearly. Use VBA to get the correct number of records in a Recordset object Issue involves the cursor used.
这里的文章http://www.geeksengine.com/article/recordcount-ado-recordset-vba.html非常清楚地解释了这个问题。使用 VBA 获取 Recordset 对象中正确的记录数 问题涉及使用的游标。
In short add this after setting: rs = New ADODB.Recordset
总之在设置后添加:rs = New ADODB.Recordset
' Client-side cursor
rs.CursorLocation = adUseClient