Errror 3021 - No current record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Petrol
    New Member
    • Oct 2016
    • 248

    Errror 3021 - No current record

    Running Access 365 under Windows 11 24H2, I am getting Error 3021 (No current record) if I delete a record from a recordset and then subsequently call a particular external procedure. The code for the sub in which the error occurs is as follows:
    Code:
    Private Sub DeauthoriseSTC( )
    ' The STC or Lagistics person will have been given read-write asccess to LiveData during the event.
    ' Now that the event is over, we remove that access - unless it was a pre-existing permanent authorisation.
    '
    Dim rst As Recordset, strNameFnSn As String
    
    On Error GoTo ErrorProc
    
    Set rst = CurrentDb.OpenRecordset("Acces sAuthority", dbOpenDynaset)
    rst.MoveFirst
    Call LogActivity("deleted Db access for " & rst!EventNum & " STC", strNameFnSn) ' TESTING ONLY
    
    Do Until rst.EOF
    If rst!EventNum <> "" Then ' ...then this authorisation was for an STC or Logistics coordinator
    strNameFnSn = DLookup("[Name_FN-SN]", "People", "PersonID = " & rst!PersonID)
    If Nz(rst!Key) = 0 Then ' Normal case - it was just an STC authorisation.
    rst.Delete ' so since the event is over, we can delete it.
    DoEvents 'TESTING ONLY
    Call StatusDescriptor(3) 'TESTING ONLY
    Call EventOffset("BSF003") 'TESTING ONLY
    Call LogActivity("deleted Db access for " & rst!EventNum & " STC", strNameFnSn)
    Else
    rst.Edit ' This person was previously an authorised user of the database
    rst!EventNum = "" ' Show as no longer an STC
    rst!AccessLevel = rst!Key
    rst!Key = 0
    rst.Update
    Call LogActivity("reverted Db access to previous level for STC", strNameFnSn)
    End If
    End If
    rst.MoveNext
    Loop
    
    ByeBye:
    rst.Close
    Set rst = Nothing
    Exit Sub
    
    ErrorProc:
    MsgBox "Error " & Err.number & " - " & Err.Description , , "Problem removing STC database access"
    Resume Next
    
    End Sub
    The error occurs on the second "Call LogActivity" statement, just after the block of 3 "TESTING ONLY" statements, which were inserted in an (unsuccessful) effort to identify the problem. (They all run without error). All three called procedues are in a different module (all in the same one).
    If I comment out the rst.Delete statement, no error occurs.
    It doesn't matter what or how many other statements I insert between that statement and the LogActivity call, the error always occurs on that LogActivity call. The LogActivity procedure is never entered (Breakpoint on the first statement not reached) - the error occurs as soon as Access tries to execute the call. As you can see I have inserted a test call to the same procedure earlier in the code, and that runs without error.
    I have tried Compact and repair and decompile/recompile - no errors on compile.
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1288

    #2
    You are referencing rst!EventNum after having deleted the record. Make your log entry before deleting the record, or capture the value of rst!EventNum in a variable before deleting the record. Then use the variable in your log entry.

    Comment

    • Petrol
      New Member
      • Oct 2016
      • 248

      #3
      Oh dear, I need a new brain. Why can't I see these things?
      Many thanks, Jim, I'm indebted to you.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Hi Petrol.

        I just sent you a Zoom invitation to the Brisbane online user group meeting in 2 hours 30 minutes.

        I look forward to meeting up if you can make it :-)

        Cheers -Ade.

        Comment

        • Petrol
          New Member
          • Oct 2016
          • 248

          #5
          Thanks for that. I didn't receive the Zoom invitation, but I found the group from one of your earlier posts to me, and have just joined.
          I would love to attend, but today doesn't work. I haev a regualr meeting Friday mornings which I can usually skip or truncate, but today I'm leading it. I may be able to slip in briefly between appointments, but I'll try to keep future meeting times free.
          Middle of the night for you?!

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            It was great fun. A little argumentative, but great fun. I'm not averse to some energetic expression of views :-)

            I sent the invitation via the PM system here (https://post.bytes.com/messagecenter/new/51203) so hopefully you'll see it.

            Comment

            • Petrol
              New Member
              • Oct 2016
              • 248

              #7
              Oh. Thank you. How should I have known I had a PM?

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                That depends on how you've configured your notification settings, though they may have changed when we were all migrated across from Bytes.com.

                If you can get them working reliably for you then it's better to continue such conversations there. I only posted in here to let you know about what was in there - as it were ;-)

                Comment

                Working...