Search code examples
crystal-reports

Suppress Section conditionally based on item in details


Lets just say i have this data in my details

  1. Item One
  2. Item Two
  3. Item Three
  4. Item Four
  5. Item Five

I want to suppress (Hidden) "Footer Section C" if there is "Item Three" in the "Detail Section".

Is there any good trick to do that ?. I have tried making a formula and place it inside details section and then pass the value into parameter field but still has no result.

I hope you can help me here. thanks

Note:

What i have been doing.

create 2 formula field one named january1 and the other one named janparameter

add formula field "january1" inside the detail section with this script inside it

WhileReadingRecords;
if {MyTable.MyItem} = "Item Three"  then
{@janparameter} = "1"
else
{@janparameter} = "0"

and in "Footer Section C" in "Suppress (No Drill Down)" i put down this script

{@janparameter} = "0"

mean that if {@janparameter} values is equal "0" then "Footer Section C" will be Suppressed. but this is not working at all for me. I hope there is someone who can solve this mistery.


Solution

  • Add following code inside the suppression-formula of the details-section:

    {MyTable.Item} = "Item Three"
    

    {MyTable.Item} should be replaced with the appropriate field of your database-table.
    Above is the short version of:

    If {MyTable.Item} = "Item Three" Then True Else False
    

    Which means, if the item is "Item Three" then suppress the section else show the section.

    EDIT 1:

    As the goal is to suppress the page footer instead of the detail section, above solution does not work.

    A parameter can not be used like it is a variable. Furthermore {@janparameter} is a formula not a parameter. Parameters start with a question mark ? not with a @.

    What the january1-formula currently does is returning True on the appropriate detail if the value of {MyTable.MyItem} is "Item Three" and the value of @janparameter is 1. If not, then False is returned.

    To achieve what you want you can use a variable.
    Replace the code of the @january1-formula with the following:

    WhilePrintingRecords;
    booleanVar ItemThreeFound;
    If {MyTable.MyItem} = "Item Three" Then ItemThreeFound := True;
    

    ...and in the suppression-formula of "Footer Section C" put the following:

    WhilePrintingRecords;
    booleanVar ItemThreeFound;
    

    EDIT 2:

    To get the opposite behavior, just add Not:

    WhilePrintingRecords;
    Not booleanVar ItemThreeFound;