如何在 VBA 中获取 RecordSet 的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25522971/
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
How to get the rows of a RecordSet in VBA
提问by Vahid
How Can I get the other rows of the RecordSet in VBA/ADO?
如何在 VBA/ADO 中获取 RecordSet 的其他行?
I'm using the below code, but that only gives me the first row. What about for example the second item on the third row of the recordset?
我正在使用下面的代码,但这只给了我第一行。例如,记录集第三行的第二项呢?
Debug.Print recordSet.Fields(0)
回答by PaulFrancis
You would need to loop through the Recordset Object to get all the rows.
您需要遍历 Recordset 对象以获取所有行。
Public Sub testRecordset()
Dim rstObj As DAO.Recordset
Set rstObj = CurrentDB.OpenRecordset("SELECT Field1, Field2, Field3 FROM tableName")
Do While Not rstObj.EOF
Debug.Print rstObj.Fields(0) & " | " & rstObj.Fields(1) & " | " & rstObj.Fields(2)
rstObj.MoveNext
Loop
Set rstObj = Nothing
End Sub
Here is the reference on how to use a Recordset Object : http://www.utteraccess.com/wiki/index.php/Recordsets_for_Beginners
以下是有关如何使用 Recordset 对象的参考:http: //www.utteraccess.com/wiki/index.php/Recordsets_for_Beginners