0
votes

I have an Access form with an attached recordset. Controls in the header adjust the recordset filters. Sometimes those filters return an empty recordset, which is OK.

However when the recordset is empty and the user clicks on any control in the header (let's say to change the filter again), Access pops up an error box with 3021 - No Current Record.

I've been unable to find the source of this error in the code - however I've added an event trigger on the form - onError for the form itself.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
    MsgBox "caught error: " & DataErr
End Sub

That works! But I had expected this sub to replace the Access error. Instead my code is executed and the original error message pops up after!

I know there are many questions about getting rid of this error but most are related to taking a VBA action - this is about removing the error when no other VBA is triggered. Is there a way to get the Form_Error sub to not show the popup?

1

1 Answers

2
votes

The simple solution is to use the Response parameter in the Form Error event. Setting it to acDataErrContinue tells it to continue and ignore the error.

You can see more examples on the doc page.