Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: How to check if data source is empty in Crystal Re Post Reply Post New Topic
Author Message
SpartanHonor
Newbie
Newbie


Joined: 13 Dec 2013
Online Status: Offline
Posts: 3
Quote SpartanHonor Replybullet Topic: How to check if data source is empty in Crystal Re
    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,
IP IP Logged
Dr4ke
Senior Member
Senior Member


Joined: 09 May 2014
Online Status: Offline
Posts: 209
Quote Dr4ke Replybullet 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.
IP IP Logged
SpartanHonor
Newbie
Newbie


Joined: 13 Dec 2013
Online Status: Offline
Posts: 3
Quote SpartanHonor Replybullet 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"
IP IP Logged
Dr4ke
Senior Member
Senior Member


Joined: 09 May 2014
Online Status: Offline
Posts: 209
Quote Dr4ke Replybullet 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?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet 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}) )


Edited by DBlank - 23 Oct 2014 at 4:14am
IP IP Logged
SpartanHonor
Newbie
Newbie


Joined: 13 Dec 2013
Online Status: Offline
Posts: 3
Quote SpartanHonor Replybullet 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.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.