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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disallow printing of report if no parameters entered... record select formula? 1

Status
Not open for further replies.

NBVC

Technical User
Sep 18, 2006
80
CA
I have a report with a paramater that allows multiple values.

When the user enters no values, then the report prints all data. I am trying to disallow printing if at least one value hasn't been entered in the parameter field.

Can I write a formula in my Record Select? Or would a formula to suppress the detail section work? If so, can you help with the formula?
 
Create a new parameter value 'All' then use this in your select.

IF {?Param} <> "(All)" THEN {TABLE.FIELD} = {?Param} ELSE TRUE

If no parameter is entered or selected, the report shouldn't print anything.

Jose
 
Thanks for that Jose. It works.

I would like to ask how I would alter that to handle a second parameter with this scenario.

So, if both are empty then don't print. If either is empty and the other is not empty, then print.

In other words, don't print only if both parameters are empty.
 
Pretty sure it's the same thing basically, just use AND between params in your select. Both would have to evaluate to TRUE for the report to print records. I don't have a report in front of me right now that uses this, but I've used it in the past and it should work. You can use this for as many parameters as you wish to evaluate.

IF {?Param} <> "(All)" THEN {TABLE.FIELD} = {?Param} ELSE TRUE

AND

IF {?Param2} <> "(All)" THEN {TABLE.FIELD} = {?Param2} ELSE TRUE
 
Hi,

I just tried that and I also was trying some nested IF combinations and they didn't work.

With your suggestion it allows print if first parameter is not empty and second parameter is empty. It does not allow printing if first parameter is empty, but second parameter is not empty. I need that to print.

FYI. My second parameter is numeric, so instead of ALL I am using 999999. Is that correct?

This is what I have, and it doesn't work for second parameter.

IF {?Param} <> "(All)" THEN {TABLE.FIELD} = {?Param} ELSE TRUE

AND

IF {?Param2} <> 999999 THEN {TABLE.FIELD} = {?Param2} ELSE TRUE

 
I'll need to look at it more closely when I'm in front of Crystal. In the meantime, hopefully someone can offer a solution. If not, I'll try to get back to you early next week.
 
I appears that you are mixing datatypes for the results of your If statement, which is not allowed in Crystal Reports (i.e., if cond then number else number, not if cond then number else boolean).
 
Hi kray4660,

Can you suggest how I should accomplish my requirement then please?
 
Opps I looked at the If statements incorrectly. You are returning Boolean in both cases ( Thought I saw the := assignment statement). Anyhow if you want Crystal to check if a parameter value has been entered. You have to use the HasValue function. Of course it helps if you are using a version of Crystal Reports that allows the use of optional prompts (I do not remember what version that was introduced).
 
Hi,

I tried the HasValue() function. Although Crystal seems to accept the formula, when I run the report from our ERP system, it errors out.

It seems to always accept the first part of the IF statement, but not the second.

For example if I enter the {?Filter_omlSalesOrderLineID} parameter, then the report runs. But if I blank out the {?Filter_omlSalesOrderLineID} parameter and enter a {?Filter_omlSalesOrderID} parameter it doesn't print anything.

Code:
IF {?Filter_omlSalesOrderLineID} <> 999999 THEN {SalesOrderLines.omlSalesOrderLineID} = {?Filter_omlSalesOrderLineID} ELSE
IF {?Filter_omlSalesOrderID} <> "(All)" THEN {SalesOrderLines.omlSalesOrderID}= {?Filter_omlSalesOrderID} ELSE  TRUE

If I reverse the above statements, then it will print only if the {?Filter_omlSalesOrderID} is entered.

The logic seems that it should work, but I don't get why it doesn't.

I also tried:

Code:
if {?Filter_omlSalesOrderID}='All' and {?Filter_omlSalesOrderLineID} = 999999 then true else
if {?Filter_omlSalesOrderID} <> 'All' then {SalesOrderLines.omlSalesOrderID} in {?Filter_omlSalesOrderID} else {SalesOrderLines.omlSalesOrderLineID} in {?Filter_omlSalesOrderLineID}

Anyone have any other ideas?

My main objective is to allow the report to run/print if either of the multi-value parameters are entered. If both are blank, then I don't want the report to print.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top