如何将select语句的结果存储在变量中?

时间:2010-02-26 18:20:09

标签: sql ms-access select variables

到目前为止我的代码是这样的。最后一行给出了一个编译错误:“期望结束语句”。

Dim strSql As String
Dim groupId As String

strSql = "Select ID from RevenueGroup where description = '" & ListO.Value & "'"
groupId = CurrentProject.Connection.Execute strSql

1 个答案:

答案 0 :(得分:4)

你正在寻找类似的东西

Dim strSql As String
Dim groupId As String

strSql = "Select ID from RevenueGroup where description = '" & ListO.Value & "'"

Dim rec As Recordset
set rec= CurrentProject.Connection.Execute strSql

groupId = rec(0)

您需要将查询结果设置为记录集,然后从结果中提取第一个值。如果没有所有已定义的变量,我无法完全编译,但这应该是一个很好的模板。

相关问题