.openrecordsource“运行时错误'91'”

时间:2011-06-01 16:27:07

标签: sql sql-server-2008 ms-access vba

我遇到以下代码行的问题,我觉得它很简单,但我不能指责它。我得到一个运行时错误'91'对象变量或块变量未设置错误。错误发生在rsc.OpenRecordSet...行。 BadgeV是一个数字,我安装了DAO引用,它是从链接的sql server表中提取的,其中我有一个主键和标识。我错过了什么?

Function FNC_Scan()
    Dim db As DAO.Database
    Dim rsc As DAO.Recordset

    Set db = CurrentDb()
    rsc.OpenRecordset ("SELECT dbo_ScanData.CardID, dbo_ScanData.Complete FROM dbo_ScanData WHERE (((dbo_ScanData.CardID)= Forms![Scan]!BadgeV))) AND ((dbo_ScanData.Complete)=0));")

    If rsc.EOF Then
        MsgBox "new item"
    Else
        MsgBox "Append Item"
    End If

    Set rsc = Nothing
    Set db = Nothing
End Function

1 个答案:

答案 0 :(得分:3)

应该是

set rsc = db.OpenRecordset(...)

而不是

rsc.OpenRecordset(...)