我正在将当前数据库中的表传递给具有2维的记录集。当前:
Public Sub MySub(obj As Variant)
Dim dbs As DAO.Database
Dim tbl As DAO.Recordset
Set dbs = CurrentDb
Set tbl = dbs.OpenRecordset("TABLE")
tbl.MoveLast
Records = tbl.GetRows(tbl.RecordCount)
Stop
...
End Sub
在我的本地窗口中逐步执行(并在立即窗口中检查),我可以看到tbl.RecordCount = 1074
,但是Records仍然只获得具有所有字段的活动记录,即Records
Type是Variant(0 to 37,0 to 0)
。
存储查询时,我可以执行类似的方法。我也尝试过语法:
Set tbl = dbs.OpenRecordset("TABLE",dbOpenDynaset)
和
Set tbl = dbs.OpenRecordset("TABLE",dbOpenTable)
前者有相同的问题,而后者返回了运行时错误'3219'。
编辑:带有查询的GetRows示例(请参阅注释)
Set dbs = CurrentDb
Set rsQuery = dbs.OpenRecordset("QUERY",dbOpenDynaset)
varRecords = rsQuery.GetRows(rsQuery.RecordCount)