简体   繁体   English

编译错误MS Access SQL

[英]Compile error MS Access SQL

I'm getting a compile error: "Argument not optional" Basically in this code, I'm trying to do a around the table style auto-assigning. 我收到一个编译错误:“参数不是可选的”基本上在这段代码中,我试图做一个围绕表格样式的自动分配。 When the code is called, it starts at AssignNullProjects() and when I get the error, GetNextAssignee is highlight in the part " & GetNextAssignee & " 调用代码时,它从AssignNullProjects()开始,当我收到错误消息时, GetNextAssignee" & GetNextAssignee & "部分中突出显示。

I'm not really sure how to fix it, here's my full code below: 我不太确定如何解决它,这是下面的完整代码:

Public Function AssignNullProjects() As Long

    Dim db As dao.Database
    Dim rs As dao.Recordset
    Dim strSQL As String

    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 SET assignedto = " & GetNextAssignee & ", assignedby = " & [Forms]![CFRRR]![assignedby] & ", Dateassigned = #" & Now & "#, actiondate = #" & Now & "#, Workername = " & _
                              [Forms]![CFRRR]![assignedto] & ", WorkerID = " & [Forms]![CFRRR]![assignedto] & " WHERE CFRRRID = " & rs!CFRRRID

            db.Execute strSQL, dbFailOnError
            rs.MoveNext
        Wend
    End If

    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing

End Function

Public Function GetNextAssignee(program As String, Language As String) As Long
'   Returns UserID as a Long Integer with the lowest [TS] value,
'   and updates same [TS] by incremented with 1.

    Dim db As dao.Database
    Dim rs As dao.Recordset
    Dim strSQL As String

    Set db = CurrentDb
    strSQL = "SELECT TOP 1 WorkerID FROM attendance WHERE [Programs] LIKE '*" & program & "*' AND [Language] = '" & Language & "' AND [Status] = '" & Available & "' ORDER BY TS ASC"
    Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    If Not rs.BOF And Not rs.EOF Then
        'Found next assignee, update date/time stamp
'        strSQL = "UPDATE tblUser SET TS = " & DMax("[TS]", tblUser) + 1 & " WHERE [WorkerID]= " & rs!workerid
        strSQL = "UPDATE attendance SET TS = " & DMax("[TS]", "attendance") + 1 & " WHERE [WorkerID]= " & rs!workerid
        db.Execute strSQL, dbFailOnError
        GetNextAssignee = rs!workerid
    Else
        'Field TS has NO VALUE FOR ALL RECORDS!
        'Code calling this function should check for a return of 0 indicating an error.
        GetNextAssignee = 0
    End If

    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing

End Function

When you call this function, you must supply 2 arguments (string values): 调用此函数时,必须提供2个参数(字符串值):

Public Function GetNextAssignee(program As String, Language As String) As Long

But when building your UPDATE statement, you call that function without supplying the required arguments: 但是,在构建UPDATE语句时,您可以在不提供所需参数的情况下调用该函数:

strSQL = "UPDATE CFRRR SET assignedto = " & GetNextAssignee & ", assignedby = "

So Access is complaining that those (string) arguments are not optional --- you must supply them. 因此Access抱怨那些(字符串)参数不是可选的---您必须提供它们。 Your code should compile when you give the function 2 strings like this ... 当给函数提供2个这样的字符串时,您的代码应编译...

strSQL = "UPDATE CFRRR SET assignedto = " & GetNextAssignee("foo", "bar") & ", assignedby = "

Although the code would compile with those strings, the function would probably not return the result you need. 尽管代码将使用这些字符串进行编译,但是该函数可能不会返回您需要的结果。 So substitute realistic values in place of foo and bar . 因此,用现实值代替foobar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM