对象必需错误MS Access SQL

时间:2015-05-14 03:42:20

标签: sql ms-access-2010

我在VBA编码中遇到了这个SQL语句。我试图用DLookUp完成更新查询,但我可能没有正确编写代码。基本上我希望WorkerIDWorkername来自用于获取此处数据GetNextAssignee("program", "Language", "username")的UserID的DLookUp。我在这里得到一个需要的对象错误:

"UPDATE CFRRR,attendance SET assignedto = " & GetNextAssignee("program", "Language", "username") & ", assignedby = " & Forms!Supervisor!NavigationSubform!assignedby.Value & ", Dateassigned = #" & Now & "#, actiondate = #" & Now & "#, Workername = " & DLookup(attendance.username, "attendance", "username = UserID") & ", WorkerID = " & DLookup(attendance.userID, "attendance", "WorkerID = UserID") & " WHERE CFRRRID = " & rs!CFRRRID

这里是上下文的完整代码:

 Set db = CurrentDb
    strSQL = "SELECT CFRRRID, [program], [language] FROM CFRRR WHERE assignedto Is Null"
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    If Not rs.BOF And Not rs.EOF Then
        While Not rs.EOF

            strSQL = "UPDATE CFRRR,attendance SET assignedto = " & GetNextAssignee("program", "Language", "username") & ", assignedby = " & Forms!Supervisor!NavigationSubform!assignedby.Value & ", Dateassigned = #" & Now & "#, actiondate = #" & Now & "#, Workername = " & _
                              DLookup(attendance.username, "attendance", "username = UserID") & ", WorkerID = " & DLookup(attendance.userID, "attendance", "WorkerID = UserID") & " WHERE CFRRRID = " & rs!CFRRRID
            Debug.Print strSQL
            db.Execute strSQL, dbFailOnError
            rs.MoveNext
        Wend
    End If

谢谢!

1 个答案:

答案 0 :(得分:0)

您的DLookup表达式不正确。 DLookup的目标字段也是字符串表达式。所以它应该是:

... & DLookup("username", "attendance", "username = UserID") & ...

SQL中出现多次此错误。

除此之外,您还应该检查标准表达式:

..."username = UserID"...

这看起来很可疑。但是,如果不了解表和数据结构,我无法判断它是否正确。