• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

How to determine if a Crystal Report contains data

I have a VB6 application and use Crystal Repots to generate all reports. The problem is that sometimes the report may contain no data based on the parameter passed to it. In those cases crystal prints a blank page with header labels ( which wastes paper). I would like to be able to test if there is data in the report before I print.

I have noticed from the tech documentation that there is a function called   GetNext Rows
which returns a rowset object. This could be used but I cannot get it to work. I attach a snippet of code
Set goCrystalApplication = Nothing
    Set goCrystalAppReport = Nothing
 
    Set goCrystalApplication = New CRAXDDRT.Application
    Set goCrystalAppReport = New CRAXDDRT.Report
    Set goCrystalAppReport = goCrystalApplication.OpenReport("ReportPath&Filename.rpt"), crOpenReportByTempCopy)
 
'   Populate Parametes
    goCrystalAppReport.DiscardSavedData
    goCrystalAppReport.ParameterFields(1).AddCurrentValue (CStr("DepartmentCode"))
 
'   I want to test if there is data in the report; If not, then don't print
    If <Test> then
'       Select Printer
        goCrystalAppReport.SelectPrinter "PrinterDriverName", "PrinterName", "PortName"
 
'       Run Printout
        goCrystalAppReport.PrintOut False, 1
    Endif

Open in new window

0
Vincent_Monaghan
Asked:
Vincent_Monaghan
  • 2
2 Solutions
 
Ido MilletProfessor of MIS at Penn State Erie and Owner, Millet SoftwareCommented:
IF goCrystalAppReport.hassaveddata Then...
0
 
Vincent_MonaghanAuthor Commented:
IdoMillet
I tried that but it returns false whethe there is data in the report or not.

One thing I did not mention is that the report uses a stored procedure to get it's data from MS SQL Server 2005
0
 
mlmccCommented:
Have you tried the REPORT OPTIONS
Chekc FILE --> REPORT OPTIONS
One of the check boxes is SUPPRESS PRINTING IF NO RECORDS.

We did this but you have to generate the report to a hidden viewer then you can print it.

Something like

If (cr_Generic_Report.RecordsPrinted <> 0) Then
Print the report

mlmcc
0
 
Vincent_MonaghanAuthor Commented:
Both answers were valid, but mimcc's worked best for me.

Thank you both
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now