Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula not displaying variable on rpt 1

Status
Not open for further replies.

RenaG

Programmer
May 3, 2011
132
US
Hi,

Using Crystal 10.

I have this formula in my report:
Code:
stringVar MedOncDoc := "N/A";

If {Config_1.Inst_Abrv} like "*MED" then
   MedOncDoc := {Staff.Initials}
else
If {Config_2.Inst_Abrv} like "*MED" then
   MedOncDoc := {Staff_1.Initials}
else
If {Config_3.Inst_Abrv} like "*MED" then
   MedOncDoc := {Staff_2.Initials};

MedOncDoc

Why does it not display "N/A" if none of the conditions are true?

~RLG
 

This should work for you. Sometimes you need the catchall at the end, sometimes you don't, but I think it's a good practice to always include it.

Code:
stringVar MedOncDoc := "N/A";
If {Config_1.Inst_Abrv} like "*MED" 
then   MedOncDoc := {Staff.Initials}
else
If {Config_2.Inst_Abrv} like "*MED" 
then   MedOncDoc := {Staff_1.Initials}
else
If {Config_3.Inst_Abrv} like "*MED" then   MedOncDoc := {Staff_2.Initials}
else
MedOncDoc;
 
I actually tried a variation of your suggestion first. I just put
Code:
else
    "N/A";
When that didn't work I tried using a variable.

I modified my code as you suggested and it still does not display the "N/A".

TIA!

~RLG
 
You probably need to check for nulls:

If not isnull({Config_1.Inst_Abrv}) and
{Config_1.Inst_Abrv} like "*MED" then
{Staff.Initials} else
If not isnull({Config_2.Inst_Abrv}) and
{Config_2.Inst_Abrv} like "*MED" then
{Staff_1.Initials} else
If not isnull({Config_3.Inst_Abrv}) and
{Config_3.Inst_Abrv} like "*MED" then
{Staff_2.Initials} else
"N/A"

Another possibility is that the formula is case sensitive and "MED" isn't always in caps. If that is the case, wrap each config_n.Inst_Abrv field in ucase().

-LB
 
That did it! Thanks so much LB.

One of these days I will remember to check for Nulls ;-)

~Rlg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top