Do not create Report if there is no Data - Within script page

Posted by: Shaun.Wilkinson on 16 August 2023, 3:32 pm EST

  • Posted 16 August 2023, 3:32 pm EST

    I am using Active Reports 7 and have no great problems using it.

    I am wanting to suppress the creation of the report when there is no data found in the SQL query used in the data source.

    At the moment in the Report Script i have the following method…

    Sub ActiveReport_NoData()

    _hasData = False

    HideReportGroups

    End Sub

    It simply hides all the sections except a group section which has the text “No data found”

    But rather than create the report with that message, Id love not to output the report at all.

    Is there a way or a line I can add to the report script that would cancel the report all together ??

    I have tried Me.Cancel but get an error…Cancel is not a member of ‘Script.ReportScript’

    What can I put in the Report Script that would just cancel the report from running ?

    Thanks in advance

  • Posted 17 August 2023, 5:02 pm EST

    Hi Shaun,

    You can stop the processing of the report using Stop() method inside the NoData event. NoData event is raised if the report’s data source does not return any records and there is no data to be processed.

    private void SectionReport1_NoData(object sender, EventArgs e)
    {
        this.Stop();
        MessageBox.Show("No Data Found!");
    }
    

    Since ActiveReports 7 is a legacy version and we do not provide support for it, I have attached a sample using ActiveReports 17. Although, the solution still remains the same.

    HideReportSR.zip

  • Posted 20 August 2023, 10:25 am EST

    Thanks for the sample.

    I really only have access to the tags in the RPX file.

    The sample RPX file you file doesnt have this method in the RPX Script.

    Is there anything you can place in the RPX file script that cancels the report execution.

    Or by the time the RPX is called is there no way to stop the report.

  • Posted 20 August 2023, 6:21 pm EST

    Hi Shaun,

    You can stop the rendering of the report via Script by calling the Stop() method inside the NoData event. It will stop the processing of the report if no records are returned from DataSource.

    Sample Code:

    public void ActiveReport_NoData()
    {
        rpt.Stop();
    }
    
    

    HideReport.zip

  • Posted 21 August 2023, 10:58 am EST

    Thanks for the Response Akshay

    I am able to add the ** rpt.Stop** to the NoData event in the RPX Script.

    Now when I execute a report with no data the report does what it syas and simply stops.

    But it doesnt seem to cancel though.

    In the report deisgner we are using it just sits there forever.

    In our application when executed it remains with a Processing Status.

    Its more like the report stops/hangs rather than gets cancelled and completes.

    Is there some tips you have that can handle the report with the rpt.Stop() in it so it returns a status of Cancelled or Completed to the reporting service calling the report ?

  • Posted 21 August 2023, 11:14 pm EST

    Hi Shaun,

    You can try cancelling the report’s processing using the Cancel method inside the NoData event. It will clear any rendered pages from the report’s Document object.

    public void ActiveReport_NoData()
    {
    	rpt.Cancel();
    }
    

    Sample:

    Alternatively, you can set the Visibility of all the sections to false in the ReportStart event to hide the report sections in order to complete the report rendering with no sections, i.e. a blank page.

    public void ActiveReport_ReportStart()
    {
             for(int i = 0; i < rpt.Sections.Count; i++)
    	 {
    	     rpt.Sections[i].Visible = false;
             }
    }
    

    HideReport.zip

    HideReport (1).zip

  • Posted 22 August 2023, 10:09 am EST

    Thanks for the suggestion.

    I did try the Cancel over the Stop but both resulted in the same outcome whcih surprised me.

    We already have handling in the script for no Data as we present a section that informs the user printing the report No Data was found.

    Was really wanting to supress the report all together though and it would appear that the Stop and Cancel functions seem to pause or freeze the report rather than cancel and complete it.

  • Posted 23 August 2023, 2:54 pm EST

    Hi Shaun,

    > I did try the Cancel over the Stop but both resulted in the same outcome whcih surprised me.

    Cancel method cancels the report’s processing and clears all the rendered pages from the report’s Document object whereas Stop method stops processing the report and retains all the rendered pages in the report’s Document.

    > Was really wanting to supress the report all together though and it would appear that the Stop and Cancel functions seem to pause or freeze the report rather than cancel and complete it.

    rpt.Cancel() doesn’t freeze/pause the report, rather it cancels the report’s processing altogether. That’s why you don’t see a report in the Viewer.

    > I did try the Cancel over the Stop but both resulted in the same outcome whcih surprised me.

    If you mean to say that even after the report has been cancelled, the application is still in processing state, this is because the form which is showing the Viewer is still running(although without any report). If you mean something else, please share with us some screenshots of the outcome that you are observing so that we can understand your concern better.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels