Solved

How to determine if a Crystal Report contains data

Posted on 2008-10-30
4
336 Views
Last Modified: 2013-12-20
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
Comment
Question by:Vincent_Monaghan
  • 2
4 Comments
 
LVL 22

Assisted Solution

by:Ido Millet
Ido Millet earned 150 total points
ID: 22841495
IF goCrystalAppReport.hassaveddata Then...
0
 

Author Comment

by:Vincent_Monaghan
ID: 22842066
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
 
LVL 100

Accepted Solution

by:
mlmcc earned 350 total points
ID: 22852126
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
 

Author Closing Comment

by:Vincent_Monaghan
ID: 31511628
Both answers were valid, but mimcc's worked best for me.

Thank you both
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now