Dino Kantardzic
Dino Kantardzic

Reputation: 107

Show All if parameter is null Crystal Reports

Hi everyone I use Crystal Reports with Visual Studio 2010 and have the following issue that I can't seem to solve. I have a parameter called name, and I make it so a user chooses from a drop down list of employee names. It is an optional parameter so the user can select nothing in which case I would like the report to show ALL the employees except for the rows that have field Employee name empty. Now I think I got the second part of it down, because I put a formula in the detail section that seems to hide all the empty employees. The problem is that if I leave the parameter unselected the report ONLY shows rows with field Employee name empty. I created a formula like so:

if not (hasvalue(({?Zaduzioc}))) then True 

    else if  
    hasvalue({?Zaduzioc})  then  
    {Inventar_Model_ReportClass.ImeZaduzioca} in {?Zaduzioc} and
    {Inventar_Model_ReportClass.Status} = "Aktivno"

Now this exact same formula works for me if I use it with a different report and parameter but that parameter has no empty values so I'm guessing it equates to something like if there are empty values show only those rows if not show everything. The problem is I can't figure out how to tell it to show everything.

Any help would be greatly appreciated.

Upvotes: 2

Views: 16981

Answers (2)

Snicklefritz
Snicklefritz

Reputation: 355

If you are selecting from a dropdown, you can add an item, Value = ALL, Description = ALL. Set your default to this value. Then in the Selection Expert, add this to your selection query:

.... AND (IF {?Parameter} = 'ALL' THEN {databasefield} = {databasefield} ELSE {databasefield} = {?Parameter})

Upvotes: 1

Dino Kantardzic
Dino Kantardzic

Reputation: 107

I managed to make it work, the problem was in the edit for the parameter I didn't set optional to true, overlooked it and as soon as I did that it all worked. So to recap for anyone with this problem: Make your parameter set optional to true, and put this in the formula for record selection:

if not (hasvalue(({?Parameter}))) then True  

else if  
hasvalue({?Parameter})  then  
{table.column} in {?Parameter}

That should be that.

Upvotes: 3

Related Questions