SAP Knowledge Base Article - Public

1487765 - How to stop a report with no data from printing

Symptom

  • Using the Crystal Reports SDK for VS .NET
  • When using PrintToPrinter function all reports print, even those with no data
  • To stop wasting a blank page, how to stop the print if no data is retrieved for the report?

Resolution

  • There are at least four options:
  1.  
    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. Retrieve the SQL query that returned the data and check if number of records returned is zero. See KBase 1280515  - How to extract SQL query from Crystal reports using RAS sdk
    3. Use the rowset controller to check number of records used in the report. See KBase 1471477  - Using the RAS SDK for VS .NET, how to determine number of data rows returned to a report?
    4. Use the following code for CR for .NET SDK:
If crReportDocument.Rows.Count > 0 Then
  crReportDocument.PrintToPrinter(1, False, 0, 0)
End if

Keywords

Forum thread , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports XI R2