Crystal report w/subreport: "Suppress Printing if No Records" is ignored by VB6

Posted on 2006-03-21
Last Modified: 2012-08-13
I created a report in Crystal Reports 8.5, which contains a subreport. However, not always there is data for the subreport for each of the records in the main report. I don't want to show the subreport for those records because the subreport contains text in the 'Details' section (I can't get rid of that text and I can't put it in the headers).

The solution on Crystal Reports is just setting the "Suppress Printing if No Records" option on. I did this, and it works great.

The problem is that when I call the report from Visual Basic 6, this option is ignored, and I get the subreport for every record in the report, regardless of whether there are records or not in it.

I am using the CRViewer object in VB (version 8.5). Just in case it has anything to do with it, the code I'm using to call the report is this:

Dim crRept As CRAXDRT.Report

' Open Report File
Set crRept = New CRAXDRT.Report
Set crRept = crApp.OpenReport(App.Path + "\reports\" + report_name)

' Logon to SQL server
crRept.Database.LogOnServer "p2ssql.dll", "ServerName", "DatabaseName", user, password

'Show the report using the object CRViewer
CRViewer1.ReportSource = crRept

Any ideas on why this is happening? Thanks!
Question by:me_ponzio
    LVL 6

    Expert Comment


    First I'd suggect to check is setting connection string for the subreport. You remember that moving a report from design to runtime environment you have to reset datasource for the report and for each of the subreports specifically.

    Thank you,

    Author Comment

    Thanks PW. I'm not sure how to do what you say, though. I am not setting any connection strings from VB to get a recordset. Instead, I created a report in Crystal Reports specifying which stored procedure to use for the main report and which sp to use for the subreport. All I'm doing from VB is connect to the database and call the report. Is that not the way to do it? Thanks.
    LVL 100

    Expert Comment

    As long as it is the same database in the exact same location it should work.  However if the database is on a different server, in a different directory, etc. you need to pass the logon information to the subreport as well.


    Accepted Solution

    It is in the same location, and the report does work and shows the same data in both Crystal Reports and from Visual Basic.

    The problem is that the report doesn't have the same behavior when run from VB as from CR. When I run it inside CR it doesn't print the subreport if it doesn't contain records from the database (which is what I want), whereas when I call it from VB, it shows the blank subreport (full of text, headers, etc!).

    I did find a workaround to this, because I need to get the reports ready ASAP. My solution is to have formula fields instead of fixed text fields, and only display those fields when there is a database record. This involves more work and time, but solves the problem.

    I still would love to know what could be wrong in VB - but if no one has suggestions on this, I'll close the question.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
    There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 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

    12 Experts available now in Live!

    Get 1:1 Help Now