1

我想操作从 sql 查询中获得的数据,然后将其写入报告中,所有这些都是使用 MS Access 中的 VBA 完成的。

所以首先我需要用这个 sql 查询获取我需要的数据

SELECT test.number_id FROM test WHERE ((test.number_id)>30));

需要将输出保存在变量中

Dim testVar As Int

做我的计算

然后我需要在报告中显示结果。

任何人都知道这是否可能以及如何做到这一点???

4

1 回答 1

1

您可以将 SQL 语句设置为记录集,然后在其中操作结果。

Dim myR2 As Recordset
Dim strSQL as String

strSQL = "SELECT test.number_id FROM test WHERE test.number_id>30"

Set myR = CurrentDb.OpenRecordset("strSQL", dbOpenDynaset)

'Manipulate myR info here'
myR.MoveFirst 'so you start from the first record'
myR.MoveNext 'to move to the next record; handy in a loop'
myR.FindFirst 'find a record in that recordset'
myR![FieldName] 'to call upon that record's field'
'Or use CREATE statement to create a new table and generate a report from it'

Set myR = Nothing
于 2013-07-24T17:37:29.213 回答