SAP Knowledge Base Article - Public

1533870 - 'Suppress Printing If No Records' using Crystal Reports .NET SDK

Symptom

  • Suppress Printing If No Records option is turned on.
  • PrintToPrinter() method is called in a Crystal Reports .NET application.
  • A blank page is printed by the printer.
  • No page should be printed as set in the Report Options.

 

Environment

  • Microsoft Visual Studio
  • Crystal Reports .NET SDK
  • Crystal Reports XI R2
  • Crystal Reports 2008

 

Reproducing the Issue

  1. Open a Crystal Report in the Crystal Reports designer.
  2. Go to File > Report Options ...
  3. Make sure Suppress Printing If No Records is selected.
  4. Click OK.
  5. Use this report in a custom application with the Crystal Reports .NET SDK.
  6. Run the report in the application such that there are no records returned.
  7. Use the PrintToPrinter() method to print the report.
  8. A blank report will be printed.

Cause

The issue has been identified and logged under Problem Report ID ADAPT00264642.

 

Resolution

There are few work arounds as follows:

  1. Check a field that will be some particular value if and only if the report has no data (e.g.; some field is NULL). If the field is NULL don't enter the print function.
  2. Another way may be to retrieve the SQL query that returned the data and check that your self to see if number of records returned is zero. This may not work if there is any client side processing being done by the report.
  3. ReportDocument has a property called Rows which can also help to get the count. See the code below
If objReport.Rows.Count > 0 Then
objReport.PrintToPrinter(1, False, 0, 0)
end if
  1. There is the rowset controller with InProc RAS. Note that InProc RAS is not available in the versions of CR that bundle with .NET and only available with CR XI R2 or 2008. See the code below:
        Dim crReportClientDoc As ClientDoc.ReportClientDocument
        Dim crRowsetController As Controllers.RowsetController
        Dim crRowsetCursor As Controllers.RowsetCursor
 
 
        crReportClientDoc = New ClientDoc.ReportClientDocument
        crReportClientDoc.ReportAppServer = "127.0.0.1"
        crReportClientDoc.Open("MyReport.rpt")
 
        crRowsetController = crReportClientDoc.RowsetController
        crRowsetCursor = crRowsetController.CreateCursor(Nothing)
 
        Me.TextBox1.Text = crRowsetCursor.RecordCount
 

 

See Also

Keywords

Suppress Printing if no records, Crystal Reports, XI R2, 2008, .NET SDK, Visaul Studio , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports 2011 ; SAP Crystal Reports XI R2