Search code examples
crystal-reports-xi

when parameter is blank show value instead crystal report xi


I have a report where I have an optional string parameter. This is Crystal Reports XI (11.0.0). In the report, I would like to display 'All' when the report is run with the parameter left blank. I have tried the following: I right click on the field -> Format Field -> Common -> Display String

if {?Location} = '' then 'all'
if IsNull({?Location}) then 'All'
if Length({?Location})< 1 then 'All'
if Length(Trim({?Location}))< 1 then 'All'

There is also nothing printed when I put
ToText(Length({?Location}))
or
ToText(IsNull({?Location}))

Also related to this question is How do I handle empty number fields/variables in Crystal Reports?
for which there was no accepted answer at the time of this submission. My googleing didn't turn up anything of worth.


Solution

  • Instead of using the Display String property, make a formula instead:

    If IsNull({?Location}) Or Trim({?Location}) = "" Then
        "All"
    Else
        {?Location}
    

    Now drop your @Formula into the report.