Invalid use of Me keyword

2020-04-14 07:38发布

This code is a function and not a private subroutine. I'm suddenly getting this error with the Me.[field name here]. I'm not getting that error in my other code, just in this one. Here's my full code without the boring end part, but I'm getting the error starting from the line:

Me.assignedby.Column(1)

Public Function AssignNullProjects() As Long

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

    assignedby = TempVars("user").Value

    Set db = CurrentDb
    strSQL = "SELECT CFRRRID 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 = " & Me.assignedby.Column(1) & ", Me.Dateassigned = #" & Now & "#, Me.actiondate = #" & Now & "#, Me.Workername = " & _
                              Me.assignedto.Column(0) & ", Me.WorkerID = " & Me.assignedto.Column(0) & " WHERE CFRRRID = " & rs!CFRRRID
            db.Execute strSQL, dbFailOnError
            rs.MoveNext
        Wend
    End If

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

What could be the possible reason for the above-stated error, and how it could be removed?

1条回答
forever°为你锁心
2楼-- · 2020-04-14 08:19

Put that code in the form's code module. When you try to use Me in a standard module, you will always get that "Invalid use of Me keyword" complaint.

Check out the "Invalid use of Me keyword" and "Me <keyword>" topics in Access' help system for further details.

查看更多
登录 后发表回答