Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: IF / Then Formula Help Post Reply Post New Topic
Author Message
dlabrec
Newbie
Newbie


Joined: 03 Jun 2008
Location: United States
Online Status: Offline
Posts: 20
Quote dlabrec Replybullet Topic: IF / Then Formula Help
     Posted: 19 Jun 2008 at 1:02pm
I have crystal report for a medical facility that is grouped by patient' snames. I have used a formula for the names since some names are very long, and others are short. Using a formula would allow the names to look uniform. If use a different field for each part of a name, I have to make the fields very wide for long names and the spacing will look bad if the names are short. (I hope that makes sense).

I want the grouping to be last name, first name, middle intial. I have created a formula for this:
{@PLast} & ", " & {@PFirst} & " " & {@PMidInt}

The problem I am running into with this formula is some patients don't have a middle initial entered in the database so their record is being excluded. I want the report to show the patients middle initial if they have one, but not exclude the record if they don't have one.

I have tried to create a if / then statment in the formula so if no middle initial is present, to list list the patient as last name, first name. But I can't get the formula correct.

Here is what I have:
{@PLast} & ", " & {@PFirst} & " " & {@PMidInt} & if {@PNameMI} = NULL then {@PLast} & ", " & {@PFirst}

When I check the validity of the formula I get an error message stating "A number, currency amount, boolean, date, time, date-time or string is expected here."

I am a newbie and probably doing this completely wrong. Any advice would be greatly appreciated.



Edited by dlabrec - 19 Jun 2008 at 1:05pm
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 19 Jun 2008 at 2:17pm

Try this:

If IsNull({@PNameMI}) then
  {@PLast} & "," & {@PFirst}
else
  {@Plast} & "," & {@PFirst} & " " & {@PMidInt}
 
-Dell
IP IP Logged
dlabrec
Newbie
Newbie


Joined: 03 Jun 2008
Location: United States
Online Status: Offline
Posts: 20
Quote dlabrec Replybullet Posted: 23 Jun 2008 at 8:44am
Thank you! The formula you posted works perfectly.
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