1

I have inherited an existing Crystal Report (.rpt) for a report that prints all records in the relevant dataset.

I now want to add selection criteria such that only the results with a matching ticket number are printed on the report.

The selection criteria I have entered is:

{REGISTER.TICKET_NO} = {?sTicketNo}

sTicketNo reflects a text value that I read from a text box in C# and pass to Crystal Reports as parameter. (The parameter passing definitely works. When I add the sTicketNo field to the report, it prints the correct value that I entered in the text box).

The problem is that no matter what selection criteria I enter, the reports never get filtered. It always prints ALL the records regardless of criteria. I have tested with other hard-coded criteria such as selecting only records with non-null values.

I have also tried the advice from C# and Crystal Reports SDK - Selection Criteria Ignored without success.

Is there perhaps anywhere else in Crystal Reports that you have to specify that you don't want all records printed? I have added my selection criteria in menu "Crystal Reports" > "Report" > "Select Expert" > "Record". I am very new to crystal reports. Maybe the author of the report added some setting elsewhere to ignore selection criteria, but I'm not sure where to look...

3
  • Not sure which version of Crystal you are running but can you go to Database > Show SQL Query and see if that includes the parameter? Also, if it's picked up the filter properly it should change the icon on the parameter in the field explorer from a bar icon to a question mark with a yellow box. May 14, 2012 at 15:09
  • It picks up the parameter. In Field Explorer, under "Parameter Fields", sTicketNo appears with the "question mark with yellow box" icon, just like it does in some of our other reports that DO successfully apply filters (and when adding the field explicitly to the report detail section to test it also contains the correct value). Yet the problem remains on this report that it includes all records and not only those matching the criteria. Maybe it has to do with the fact that the field (string) contains special characters (/) but I don't expect so.
    – Stanley
    May 15, 2012 at 5:04
  • It sounds more like a bug rather than something you've overlooked or an error you've made. The only other option I can think is to re-construct the report select statement directly in SQL with the same filter applied. May 15, 2012 at 9:52

1 Answer 1

15

Had the same problem - found this solution. Worked for us for VS 2010 even though it mentions VS 2005/2008.

Symptom

When upgrading a VS .NET application to use Crystal Reports 2008 in Visual Studio .NET 2005, the selection formula (.RecordSelectionFormula) is ignored.

Cause

In Visual Studio .NET 2005, when the Crystal Windows Form Viewer is added to a Windows Form, the auto-generated code adds two lines of code that set the selection formula to an empty string (""). The viewer's SelectionFormula and ViewTimeSelectionFormula are set to "" by default, thus, the application will ignore selection formulas, be it in the report designer or passed to the report at runtime.

Resolution

To resolve the issue, follow these steps:

Expand Form1.vb|cs to show Form1.Designer.vb|cs. (form1 denotes the form that contains your viewer)

Double-click on Form1.Designer.vb|cs to show its code.

In the InitializeComponent method, you will find code where the CrystalReportViewer1 properties are set.

Comment out or delete the following two lines:

me.crystalReportViewer.SelectionFormula = ""

me.crystalReportViewer.ViewTimeSelectionFormula = ""
3
  • 2
    Thanks a lot. I had no idea what's going on - I loaded parameters to report and it didn't refresh.Helped me with C# too. In my project I switched Crystal libraries to newer ones and it seems I have to do some serious trash cleaning now. CR really suck quite often.
    – RRM
    Jan 29, 2016 at 17:53
  • not working for me even after commenting. any other ideas?
    – webzy
    Feb 18, 2016 at 19:47
  • Thank you! Great answer! May 13, 2019 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.