cancel
Showing results for 
Search instead for 
Did you mean: 

vb.net2008 CR suppress print if nothing selected

Former Member
0 Kudos

In Crystal Reports Designer XI there is an option which suppress print if no data is selected.

So nothing happens if you print to printer and there is no data selected.

Is there a possibility having this behavior in my vb.net2008 CR application?

Using PrintToPrinter() with no data selected always prints a blank page.

I use following code:

Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument

objReport.Load("example.rpt")

.

.

.

objReport.PrintToPrinter(1, False, 0, 0)

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member188030
Active Contributor
0 Kudos

Hi,

I am not clear about the statement ".......no data is selected" please elaborate on that.

Are you trying to suppress a section or a report object displaying some data?

Thanks,

Bhushan.

Former Member
0 Kudos

That means the sql returns no rows. In that case an empty page is printed. And that empty page I want to suppress.

No rows retuns -> no page is printed.

Thanks

former_member183750
Active Contributor
0 Kudos

You will have to upgrade to CR 2008 (12.x) and use the InProc RAS SDK, RowsetController. CR 105 which bundles with .NET 2008 does not include the RAS SDK.

Ludek

former_member208657
Active Contributor
0 Kudos

It looks like this is something which was tracked (ADAPT00264642) but never resolved. I'll look into this and see what can be done.

former_member208657
Active Contributor
0 Kudos

A small clarification here. If a fix is developed for this it will likely be for Crystal Reports 2008 and future products.

Former Member
0 Kudos

Does that mean, that this is a known problem without solution now and in the future for my used version of CR?

Thanks.

former_member208657
Active Contributor
0 Kudos

I don't know what you mean by the comment below, but I'll reiterate:

>

> and in the future for my used version of CR?

I was able to reproduce the behavior and found an old track in our database for this issue. The issue wasn't resolved in previous versions of Crystal Reports so I've tracked it for Crystal Reports 2008. Older versions like 10, XI R1, and XI R2 are no longer eligible for patch support so they won't be fixed.

There are no guarantees that this will be resolved. Our product team needs to investigate this issue and see what they can do to fix it.

Former Member
0 Kudos

I'm also concerned.

In VB6 using CR through RDC there was a turn around couting the number of record of the report :


Dim CrRep As New CRAXDRT.Report 
...
Dim NbRecordRead as integer
NbRecordRead = CrRep.PrintingStatus.NumberOfRecordRead

If CrRep.PrintingStatus.NumberOfRecordRead > 0 Then
    CrRep.PrintOut (False), 1
End If
...

But I can't find this property in .net model

Any help ?

Yoann

former_member183750
Active Contributor
0 Kudos

No API like that in the CR SDK for .NET at this time. A possible way to work around this is to 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.

Another way may be to retrieve the SQL query that returned the data and check that your self to see if number of records returned is zero. Obviously this may not work if there is any client side processing being done by the report. But that would have been the case in the code you provided anyhow.

And then of course there is the rowset controller with InProc RAS. Note that InProc RAS is not available in the versions of CR that bundle with .NET.

Ludek

Former Member
0 Kudos

That is the solution for me.

Using:

If objReport.Rows.Count > 0 Then

objReport.PrintToPrinter(1, False, 0, 0)

end if

solves the problem for me.

Many thanks

former_member208657
Active Contributor
0 Kudos

Here is some code I used in the past to get the record count using the RAS .NET SDK. This is only available if you are using XI R2 or 2008.


        Dim crReportClientDoc As ClientDoc.ReportClientDocument
        Dim crRowsetController As Controllers.RowsetController
        Dim crRowsetCursor As Controllers.RowsetCursor


        crReportClientDoc = New ClientDoc.ReportClientDocument
        crReportClientDoc.ReportAppServer = "127.0.0.1"
        crReportClientDoc.Open("Product Catalog.rpt")

        crRowsetController = crReportClientDoc.RowsetController
        crRowsetCursor = crRowsetController.CreateCursor(Nothing)

        Me.TextBox1.Text = crRowsetCursor.RecordCount

Former Member
0 Kudos

@ Reiner Duffner

Thanks for the answer, I found the rows.count method just after I post the message.

I saw somewhere in SAP CR forum someone who had some problem with this method and report containing sub-report, but after some tests its seems to be OK for me.

@Ludek Uher

@David Hilton

Thanks also I'me currently using CR XI R2 (not .net bundled) so I can use RAS, is this method better than reportDoc.Rows.count ?

former_member208657
Active Contributor
0 Kudos

I didn't realize the ReportDocument.Rows was there. It must have been snuck in at some point and I didn't notice it. The only issue I see with the Rows property is that it isn't documented. That means its functionality could change without notice. It is, however, a quick and easy indicator to check whether there are any records in the main report.

former_member208657
Active Contributor
0 Kudos

Sorry for the late reply on this issue. The product development team reviewed the problem (ADAPT00264642) with the suppress printing no records and have decided to not fix it for the current version of the product. There are too many changes to make at this time so they will look at this for future releases of Crystal Reports.

The notes indicate this isn't fixed in Crystal Reports for Visual Studio 2010 either. I will follow up with the project manager to see if it can be looked at again.

Answers (0)