Print Page | Close Window

How to check if data source is empty in Crystal Re

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21127
Printed Date: 01 May 2024 at 5:34pm


Topic: How to check if data source is empty in Crystal Re
Posted By: SpartanHonor
Subject: How to check if data source is empty in Crystal Re
Date Posted: 22 Oct 2014 at 10:34am
so I have a formula that looks like this:

    ToText({ProjectedHours.StartDate},{?Pm-?ShortDateFormat}) + " - " + ToText({ProjectedHours.EndDate},{?Pm-?ShortDateFormat})

ProjectedHours is the data source that I'm passing in from C#/.NET. The problem is that it is possible for ProjectedHours to be empty. Is there a way for me to basically to conditionally execute the code above only if ProjectedHours is not empty?

I actually tried this as well. Since I'm using C#/.NET, I can detect if ProjectedHours is empty or not. If it is, I simply set a parameter called HideProjectedHours to true, else false. And in Crystal, I have the following code:

    If {?Pm-?HideProjectedPaidHours} = false Then
    ToText({ProjectedHours.StartDate},{?Pm-?ShortDateFormat}) + " - " + ToText({ProjectedHours.EndDate},{?Pm-?ShortDateFormat})

However, this doesn't work either and I get the error message "Too many arguments have been given to this function. Details: errorKind


Thanks,



Replies:
Posted By: Dr4ke
Date Posted: 22 Oct 2014 at 9:53pm
Have you tried using the IsNull function?

If Not(Isnull({Field}) Then {Formula}

You'll have to play around with it a bit as I can't remember the exact syntax off the top of my head.


Posted By: SpartanHonor
Date Posted: 23 Oct 2014 at 1:50am
Hi,

I just tried that. I got the same error message:

"Error in formula StartDate: 'If not(IsNull({ProjectedHours.StartDate})) Then 'Too many arguments have been given to this function. Details: errorKind"


Posted By: Dr4ke
Date Posted: 23 Oct 2014 at 1:54am
You haven't told the formula to do anything if the condition is true (it looks like).

Look at the IF command syntax 'If X Then Y [Else Z]'. The Else Z is optional if I remember correctly.

If you do have a Then statement - what is your whole formula?


Posted By: DBlank
Date Posted: 23 Oct 2014 at 4:14am
I would test the formula without the if-then
ToText({ProjectedHours.StartDate},{?Pm-?ShortDateFormat}) + " - " + ToText({ProjectedHours.EndDate},{?Pm-?ShortDateFormat})
and see if the error is in regards to the use of the parameter ?Pm-?ShortDateFormat as you format condition.
 
If that runs fine then try and wrap that in parenth as your THEN portion
 
IF NOT(ISNULL({ProjectedHours.StartDate})) THEN
(ToText({ProjectedHours.StartDate},{?Pm-?ShortDateFormat}) + " - " + ToText({ProjectedHours.EndDate},{?Pm-?ShortDateFormat}) )


Posted By: SpartanHonor
Date Posted: 23 Oct 2014 at 4:35am
Hi,

Problem solved. It seemed that in my C# code, I could simply not add a data source to my subreport if the data source is empty (count = 0). By not adding a data source to the subreport, I stopped seeing the error message. Basically, my orginally problem was that a formula in a subreport was throwing a crystal reports error even though I was suppressing that subreport.



Print Page | Close Window