Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Dec 2009
    Location
    Bogangar NSW Australia
    Posts
    154
    Thanks
    29
    Thanked 3 Times in 2 Posts

    Question Access 2010 VBA: "The OpenReport action was canceled"

    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




  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    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
    Regards
    John



  3. #3
    2 Star Lounger
    Join Date
    Dec 2009
    Location
    Bogangar NSW Australia
    Posts
    154
    Thanks
    29
    Thanked 3 Times in 2 Posts

    Thumbs up Access 2010 VBA: "The OpenReport action was canceled"

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •