如何在 VBA/ADO 中获取 RecordSet 的其他行?
我正在使用下面的代码,但这只给了我第一行。例如,记录集第三行的第二项怎么样?
Debug.Print recordSet.Fields(0)
最佳答案
您需要循环遍历 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
以下是有关如何使用 Recordset 对象的引用:http://www.utteraccess.com/wiki/index.php/Recordsets_for_Beginners
关于vba - 如何在VBA中获取RecordSet的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25522971/