Print Page | Close Window

If statement not working

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2022
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=12396
Printed Date: 31 Mar 2025 at 12:35am


Topic: If statement not working
Posted By: bishop14772
Subject: If statement not working
Date 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.

 



Replies:
Posted By: bishop14772
Date Posted: 24 Feb 2011 at 4:38am

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



Posted By: rickymartin06
Date 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)


Posted By: lockwelle
Date 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
 


Posted By: bishop14772
Date 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.


Posted By: DBlank
Date 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 ...
 



Print Page | Close Window