Share via

Microsoft Access Error Opening Report

Anonymous
2023-01-27T16:12:56+00:00

Microsoft Access - I have an Error Trap that catches a First Error, but on a second Error Number 2501 Opening a Report, that has a No Data routine and cancels the opening of the Report, this second error is not trapped and I cannot seem to figure out how to get it to a Error Trap Routine.

Microsoft 365 and Office | Access | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2023-01-27T20:05:12+00:00

    What does the code look like?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-01-27T17:38:00+00:00

    I have an Error Trap to catch Err.Number 3021 so I get the Last Record that ran, it refers to a GoTo..., this works fine when there is data. When it goes to the GoTo it Opens a Report, when there is No Data, the Report has the NoData Event that tells the End User there is No Records for that user. In this Sub it also has a CancilEvent, when it Returns to the Calling Sub Rutine is when the error occurs, it stops on the OpenReport command with the Error Number 2501. It will not go to the Error Trap, it does a Popup.

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2023-01-27T16:43:20+00:00

    Do you get this error in a procedure that opens the report using DoCmd.OpenReport?

    If so, use something like this:

    Private Sub cmdOpenReport_Click()
        On Error GoTo ErrHandler
        DoCmd.OpenReport ReportNsme:="MyReport", View:=acViewPreview
        Exit Sub
    ErrHandler:
        Select Case Err.Number
            Case 2501
                ' Opening the report was canceled; we can ignore this
            Case Else
                ' Show the error
                MsgBox Err.Description, vbExclamation
        End Select
    End Sub
    

    Was this answer helpful?

    0 comments No comments