• Access 2010 VBA: “The OpenReport action was canceled”

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Access 2010 VBA: “The OpenReport action was canceled”

    Author
    Topic
    #479507

    I have a report that in Private Sub Report_Load() and Private Sub ReportHeader_Format tests for certain parameters and if not found to exist it then exits the Subs because there is no data to generate in the detail of the report. Because there is no data I run the following:

    Private Sub Report_NoData(Cancel As Integer)

    Msg = “Select a Supplier” & vbCrLf & vbCrLf & “Cancelling Report…”
    Button = vbExclamation
    Title = “Account Report Error 1…”
    Response = MsgBox(Msg, Button, Title)

    Cancel = True

    End Sub

    This sub displays the message as desired, but on clicking OK the following a MS Access error dialogue advising “The OpenReport action was canceled” is displayed. How do I stop this dialogue from being displayed?

    I’ve tried inserting an error procedure in the Private Sub Report_NoData() but that just seems to be ignored.

    Any suggestions will be appreciated.

    Regards

    BygAuldByrd


    [/COLOR]

    Viewing 0 reply threads
    Author
    Replies
    • #1302213

      Add an error handler, to the code that opens the report, that handles error 2501.
      Something along these lines.

      If err.number =2501 then
      Resume cmdOpenreport_exit
      else

      msgbox err.description

      Resume cmdOpenreport_exit
      end if

      • #1302324

        Hi John,

        Many thanks for your prompt resonse. It pointed me in the right direction to solve my problem.

        I had been looking for the problem in the Report code, whereas I should have been looking in the Form that is used to select and initiate the Report viewing process. That Form has a Command Button on it called “View Report” and I finally resolved my problem with the following code attached to that Command Button, which I post below to help others trying to solve this problem (I’d been chasing my tail for hours).

        Private Sub Cmd_View_Report_Click()

        ’ *** Subroutine to View Report
        On Error GoTo Error_SubCmdViewReportClick

        Dim Msg, Button, Title, Response As String

        ’ *** Insert any processes required before Viewing the report, for example:
        Me.Tbx_Club_Name = Me![Cbo_Select_Club].Column(1)
        If IsNull(Me.Tbx_Club_Name) Then
        Msg = “Please select a Club”
        Button = vbExlamation
        Title = “View Report…”
        Response = MsgBox(Msg, Button, Title)
        GoTo QuitSubCmdViewReportClick
        End If
        ’ *** END Insert any processes required before Viewing the report

        ’ *** Open the Report in Preview View mode
        Dim strReport As String
        strReport = Tbx_Report_Name
        DoCmd.OpenReport strReport, acViewPreview
        ’ *** END Open the Report in Preview View mode

        ’ Label to GoTo if a premature Sub exit is initiated by an earlier process or a subroutine
        QuitSubCmdViewReportClick:

        Exit Sub ’ Needed before the subroutines or thet will be processed again

        ’ *** Subroutines
        Error_SubCmdViewReportClick:
        If Err.Number = 2501 Then
        Resume QuitSubCmdViewReportClick
        Else

        ’ Use a short form error message:
        ‘ MsgBox Err.Description
        ‘ Or a more vebose but descriptive error message to assist in finding the problem:
        Msg = “Private Sub Cmd_View_Report_Click() Error 1…” & vbCrLf & _
        vbCrLf & “Access VBA Err.Number = ” & Err.Number
        Button = vbExlamation
        Title = “View Report…”
        Response = MsgBox(Msg, Button, Title)
        Resume QuitSubCmdViewReportClick
        End If
        ’ *** END Subroutines

        End Sub ’ *** END Subroutine to Private Sub Cmd_View_Report_Click()

        Thanks again for the assistance.

        Cheers

        BygAuldByrd

    Viewing 0 reply threads
    Reply To: Access 2010 VBA: “The OpenReport action was canceled”

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: