Solved

How to determine if a Crystal Report contains data

Posted on 2008-10-30
4
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 4 71
Zip Folders Using Chilkat Routines 1 76
adding "ungroup sheets" to existing vbs code 5 57
Crystal Reports 2013 - outer join - missing rows that don't match 7 23
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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