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:
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.
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
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.
Comment