Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No Preview for Blank Reports

Status
Not open for further replies.

mdwg2020

Programmer
Feb 17, 2005
51
US
Hey guys,

Quick question, I'm building a VB application that will open up a form with a crystalReportsViewer in it to preview reports depending on the parameters the application passed to it. Is there a method that I can invoke to first tell if there will be any records? If there are no records I would prever to just display a messageDialog box telling the user that there are no records for that specific request, instead of opening a new form with a blank report in it.

Thanks,

Brooks
 
Assuming you're using the RDC, you can force a read on the records, then check to see if any records were returned:
Code:
crxRpt.ReadRecords
If crxRpt.PrintingStatus.NumberOfRecordSelected = 0 Then
    MsgBox "No Records Returned"
Else
    'Send the report to the Viewer
    CRViewer.ReportSource = crxRpt
    CRViewer.ViewReport 
End If
... where crxRpt is your Report object, and CRViewer is the name of your CRViewer control.

-dave
 
Thanks Dave,

I will try that and let you know. I guess I will have to build the report object in my mainForm, and then open access up to the CRViewer, so I can test before I actually show the form. Get back shortly, I hope!

Brooks
 
Hey,

I attempted to create a report object by doing the following:

Dim tranReport As New Transcript

where Transcript is the name of a crystal report that I have in my project.

However, when I attempt the following:

tranReport.ReadRecords()

it tells me that ReadRecords is not a member of Transcript. Am I creating the object incorrectly? Or are there some classes that I need to import? Sorry, just lost my way a little!
 
Another question,

I keep running the report and it works appropriately, however, it asked me for a user name and password.

I added the connection for the report in Visual Studio. I also tested it out by actually creating a connection to the database using a connection string, and that didn't work either.

Any help on this, or have you gone through this before?
 
Hey Dave,

This one is written in .NET. I now have it reporting, the only things that I still haven't be able to accomplish is making it stop asking me for a connection username and password, and testing for records before I print the report.
 
Well, I finally figured how to use crystal connection info so that it never asks me for the logon name and password, but I'm still short figuring out if a report has records before I preview it. The best that I have done, is modify the report so that it says to the user "No Records To Display", and nothing else, I would like to prevent the report all together.

Any ideas? I attempted to do the ReadRecords, but that method didn't work for me.
 
I don't know if there's a way to do this using .NET. I poured over the SDK for 20 minutes earlier, but didn't see anything. I would say there's got to be a way, but this wouldn't be the first thing I've seen that's easily done using the RDC, but non-existant with the .Net assemblies.

-dave
 
Thanks Dave, I have actually completed the rest of the application. They will just have to deal with the blank report that tells them there are no records. Other than that I finally got everything that I needed to work. Thank you very much for all of your help!

Brooks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top