Run - Time Error 3021 "No Current Record"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Laneyshia
    New Member
    • Dec 2010
    • 9

    Run - Time Error 3021 "No Current Record"

    Hello Again.

    I have been proceeding through my code, thanks to you guys, and although this particular line may not be needed it is giving me this error that does not make sense.

    When asked to print a msgbox with the content of a particular field after inserting and updating a new record it states that there is not current Record.

    Could anyone explain or tell me what I'm doing wrong?

    Thank you,

    You may not know it but you guys have made my New Years!!
  • Laneyshia
    New Member
    • Dec 2010
    • 9

    #2
    Sorry Code is Below:

    Code:
        Dim JMP As String 'Jobs Main Positions
        Dim EMP As String 'Employee Main Positions under NotAbsent
        
        While Not Jobs.EOF
            JMP = Jobs![Main Positions]
            MsgBox "JMP: " & JMP
            
            While Not NotAbsent.EOF
                EMP = NotAbsent![Main Positions]
                MsgBox "EMP: " & EMP
                
                If EMP = JMP Then
                    
                    Schedule.AddNew
                    Schedule![First Name] = NotAbsent![First Name]
                    Schedule![Last Name] = NotAbsent![Last Name]
                    Schedule![Main Positions] = NotAbsent![Main Positions]
                    'Schedule![Replacement Positions] = NotAbsent![Replacement Positions]
                    
                    Schedule.Update
                    MsgBox "Schedule: " & Schedule![First Name]
        
                    
                End If
                
                NotAbsent.MoveNext
            Wend
            
            Jobs.MoveNext
        Wend
    Also you may see one line of code that is commended out; I have this error that states "Item Not Found In This Collection" 3265. The line before it have all been copied and pasted and only the content in the [] would be provoking the error. After checking spelling error and finding nothing wrong, I'm not sure what it could be.

    Thank you again!

    Comment

    • Stewart Ross
      Recognized Expert Moderator Specialist
      • Feb 2008
      • 2545

      #3
      Hi. You'll need to do some line-by-line walk throughs of your code to see what is going on. Set a break point at, say, the IF statement in line 13 and then single-step through the code looking at the values of all fields to see what is going wrong.

      I'd surmise that if all is working OK until line 21 - the update statement - then the update itself failed. This can happen if you have attempted to insert a record that breaks a relational constraint on the table concerned, or that would create a duplicate key for example.

      Regarding the 'item not found in this collection' error, this is telling you that the field name concerned ([Replacement Positions]) is not correct - either the field does not exist in one or both of the two recordsets, or it is spelled differently. Why the error message mentions 'collection' is that when using recordsets the VB compiler is iterating through the fields collection of the recordset to match the names of the fields as you have listed them; if it can't find a match it generates the error you have mentioned.

      For a more detailed guide on how to use the VBA editor's debugging facilities please see our articles on Debugging in VBA.

      -Stewart
      Last edited by Stewart Ross; Dec 31 '10, 07:44 AM.

      Comment

      Working...