Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: IF statement Post Reply Post New Topic
Author Message
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Topic: IF statement
     Posted: 21 Mar 2012 at 4:58am
Hi,

I've got a problem with the report I created. It is possible that a client has more then 1 contact person. If this happens, we want to show both of them on the report. In the database, the second contact person is stated by code =7. If it is anything else then 7, it is the first contact, if it is 7 it is the second.

I created a formula, stating that if this code is 7, and the the name is filled in, then I want to show the name. But when I run this formula, I got 2 letters. 1 with only the first contact, and 1 with both contacts. The formula looks like this:

IF{Client.code}=7 AND NOT ISNULL({Contact.firstname}) AND NOT ISNULL({Contact.lastname}) THEN
{Contact.firstname} & Chr (13) & Chr(10) & {Contact.lastname}

But it looks like after the THEN statement, it doesn't look like it is looking at the IF statement. Does anyone know what I mean? And can anyone help me with this?

Thanks in advance

Gerben
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 21 Mar 2012 at 5:16am
I've been messing around a little bit, and I found out that is has something to do with the linking of the different tables. There is a table, linking the Client information to the letters. But because the letter code isn't a unique value, it's showing up twice...
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 22 Mar 2012 at 12:00am
Never mind, after working on this again this morning, I found out that the database is set up in a different way then that they told me... so the problem is in the database instead of CR.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 22 Mar 2012 at 8:30am
just as a note, check for isnull first... not that it affects this, but as a rule.
something like
if {table.field} = x or isnull({table.field}) then
 
will never work. CR will 'silently' throw an error and ignore this code if {table.field} is null. 
 
WHY?  I believe that CR sees null = x (which makes no sense, and so errors out).  But to be nice to us users, it ignores the error, but doesn't process the statement
 
but if we change the order to be
if isnull({table.field}) or {table.field} =x then
 
life is fine...
 
just a thought to remember for future reports
 
IP IP Logged
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