Search code examples
if-statementcrystal-reportsconditional-statements

Crystal Reports conditional text output


ExampleI have been asked to write a formula that will conditionally display text on a single field if item numbers on an order are a of a certain value.

So if any of the items on an order match the following values:

>{oeordlin_sql.item_no} = '022471-2000'
>{oeordlin_sql.item_no} = '142846-003'
>{oeordlin_sql.item_no} = '202522-2000'
>{oeordlin_sql.item_no} = '022468-2000'
>{oeordlin_sql.item_no} = '022471-2000'
>{oeordlin_sql.item_no} = '202522-2010'
>{oeordlin_sql.item_no} = '202258-01'
>{oeordlin_sql.item_no} = '142845-002'
>{oeordlin_sql.item_no} = '142847-20204'
>{oeordlin_sql.item_no} = '142848-01402'
>{oeordlin_sql.item_no} = '142848-01408'
>{oeordlin_sql.item_no} = '142849-001'

Then return a text line saying "Class VI Certification Required" Otherwise nothing should be printed.

Currently I have:

If {oeordlin_sql.item_no} = '022471-2000'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '142846-003'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '202522-2000'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '022468-2000'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '022471-2000'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '202522-2010'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '202258-01'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '142845-002'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '142847-20204'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '142848-01402'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '142848-01408'
Then "Class VI certificate Required"
else if {oeordlin_sql.item_no} = '142849-001'
Then "Class VI certificate Required"
else ""

This works to a point, but it generates extra pages for every part, the report should be a single page. How can I get this to print out the text field on the single page if any of the part numbers match without it generating a new page for each?


Solution

  • I was able to get this to work by using edit formula:

    If {oeordlin_sql.item_no} = '022471-2000'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '142846-003'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '202522-2000'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '022468-2000'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '022471-2000'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '202522-2010'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '202258-01'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '142845-002'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '142847-20204'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '142848-01402'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '142848-01408'
    Then "Class VI certificate Required"
    else if {oeordlin_sql.item_no} = '142849-001'
    Then "Class VI certificate Required"
    else "suppress"
    

    then going to select expert: and setting @Class VI Cert to "is not equal to 'suppress'"

    then Format field: Suppress If Duplicated