Print Page | Close Window

Optional Parameters in formulas

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=8446
Printed Date: 05 May 2024 at 2:54pm


Topic: Optional Parameters in formulas
Posted By: bff7755a
Subject: Optional Parameters in formulas
Date Posted: 23 Nov 2009 at 6:39am
How can I check, if the optional parameter present.

When I try use this code:

if not IsNull({@DATERUN}) then
    formula = DateTimeValue ({@DATERUN})
else
    formula = DateTimeValue(0)
end if

I have an error when I run a report with no value for parameter DATERUN.



Replies:
Posted By: DBlank
Date Posted: 23 Nov 2009 at 2:58pm
Do you mean how can you return all values if nothing is selected or = to whatever day is selected? I do not see your parameter in your code so I going to gess your formula was meant to be the parameter.
In the select expert use I think you could use:
IsNull({?DateRun}) or {?DateRun}={table.datefield}


Posted By: bff7755a
Date Posted: 23 Nov 2009 at 11:00pm
Originally posted by DBlank

Do you mean how can you return all values if nothing is selected or = to whatever day is selected? I do not see your parameter in your code so I going to gess your formula was meant to be the parameter.
In the select expert use I think you could use:
IsNull({?DateRun}) or {?DateRun}={table.datefield}


Sorry. I mean, {?DateRun}, of course. The problem is that when DateRun is not set, I couldn't use IsNull() for testing it. Crystal says "Parameter value not defined".


Posted By: foyst
Date Posted: 24 Nov 2009 at 5:32am
Have you tried using HasValue instead of IsNull?
 
if HasValue( mailto:%7b@DATERUN - {?DATERUN }) then
    formula = DateTimeValue ( mailto:%7b@DATERUN - {?DATERUN })
else
    formula = DateTimeValue(0)
end if
 
Believe that should do it, apologies if not I didn't get chance to test it!
Note that I believe this function only came about in Crystal Reports 2008, so won't work in earlier versions.
 
HTH


Posted By: DBlank
Date Posted: 24 Nov 2009 at 6:46am
I think some versions do not allow you to leave an empty param at run time. If the param is in the report you have to enter a value.
If this is the case try using a default value (like 01/01/1900) which in your select statement would be set to ignore the value (like the ISNULL).
{?DateRun}=Date(1900,01,01) or {?DateRun}={table.datefield}



Print Page | Close Window