Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: If statement not working Post Reply Post New Topic
Author Message
bishop14772
Newbie
Newbie


Joined: 22 Feb 2011
Online Status: Offline
Posts: 3
Quote bishop14772 Replybullet Topic: If statement not working
    Posted: 22 Feb 2011 at 3:24am

I have a problem I am making a report card report, where teachers can pull information off the gradebook server and comment in individual classes for students.

My problem is that I have located all the necessary tables in the database but when i throw the if else statement into the report it will only show the classes that have comments when the report is run.  Instead of showing all 9 classes it will only show the ones that have been commented on.  I had the idea of an empty else statement but cant locate how to do that.  Any ideas??? here is my code.
 
shared stringvar ck111com1;

If {Comments.CommentNum} = {Grade2S.111COM1_Letter}
             Then ck111com1  := ('MP1 - Comment: ' + {Comments.CDescription})
 
 
 
The report will run but will leave out lots of information.

 


Edited by bishop14772 - 22 Feb 2011 at 4:14am
IP IP Logged
bishop14772
Newbie
Newbie


Joined: 22 Feb 2011
Online Status: Offline
Posts: 3
Quote bishop14772 Replybullet Posted: 24 Feb 2011 at 4:38am

Does anyone think that it could be because of a bad link between DB tables?

IP IP Logged
rickymartin06
Newbie
Newbie
Avatar

Joined: 16 Feb 2011
Location: Puerto Rico
Online Status: Offline
Posts: 3
Quote rickymartin06 Replybullet Posted: 24 Feb 2011 at 10:03am
well i dont know if this is your problem but once i had a problem with null values, crystal reports hate null values and instead of displaying sometimes it will not show any records, if that is the case you will have to use the formula or function ISNULL() try in the else isnull(ck111com1)
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 24 Feb 2011 at 10:36am
if it displays without the if statement, it is not the join.
I would try something like:
shared stringvar ck111com1;
 
if Not ISNULL({Comments.CDescription}) then
   If {Comments.CommentNum} = {Grade2S.111COM1_Letter}
             Then ck111com1  := ('MP1 - Comment: ' + Comments.CDescription})
 
also, you realize that this will only display 1 comment, as it continually overwrites the value...which if fine, if that is what you wanted.
 
always check for nulls first, as CR doesn't behave well with nulls in formulas (well, at least not the way one expects)
HTH
 
IP IP Logged
bishop14772
Newbie
Newbie


Joined: 22 Feb 2011
Online Status: Offline
Posts: 3
Quote bishop14772 Replybullet Posted: 25 Feb 2011 at 2:48am

Thank you for the ideas but its still not working.  I kind of understand what you guys were saying with the isnull formula so I will try to figure out a couple more things using that.  Ive been pulling my hair out on this for to many weeks now.  Any more ideas i'll try anything.

 
It will still only print the classes that have comments in them even with this formula
 
shared stringvar ck111com1;
 
if Not ISNULL({Comments.CDescription}) then
   If {Comments.CommentNum} = {Grade2S.111COM1_Letter}
             Then ck111com1  := ('MP1 - Comment: ' + {Comments.CDescription})
 
 
Im going to try a few things.
 
Also,
"also, you realize that this will only display 1 comment, as it continually overwrites the value...which if fine, if that is what you wanted."
 
I found that it actually placed multiple comments on the classes so it will work i just gotta figure out how to get the classes that dont have comments on them to show up.
 
The Comments.CDescription and Comments.CommentNum fields do not contain null values, Grade2S.111COM1_Letter does.


Edited by bishop14772 - 25 Feb 2011 at 3:51am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Feb 2011 at 4:41am

I will partially disagree and say this is likely a join problem ...

if your "if then" formula is the first time you are using any field from one of the tables in the report then it is the first time that the join is being enforced and it will potentnially make records disappear.
To test this, drag and drop a field from each of the tables onto the report canvas while in preview mode and see if any records disappear.
If they do you likely need to change one of your joins to an outer join and/or maybe alter a select statement.
 
That being said once you correct that problem the NULLS will eventualy cause you similar issues later in your formula which. You will address that by most likely changing the first part of your statement to handle the correct isnull field from the outer join...
if Not ISNULL({Grade2S.111COM1_Letter}) then ...
 


Edited by DBlank - 28 Feb 2011 at 4:44am
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.