Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

If statements in Crystal Reports

Posted on 2009-12-21
4
Medium Priority
?
364 Views
Last Modified: 2012-05-08
Hi

Can someone help with the formula below.  I am trying to get the address to show in one text box.  If all fields have data, all show in the text box on the report but if one is blank then from the blank field on does not display (eg. if add3 = "" then nothing else will show on the report after add2, but if its present all data shows.

Please help,

CSTR({Customer.customer_Add1}) &
IF CSTR({Customer.customer_Add2})="" THEN "" ELSE CHR(13) & CSTR({Customer.customer_Add2}) &
IF CSTR({Customer.customer_Add3}) ="" THEN "" ELSE CHR(13) & CSTR({Customer.customer_Add3}) &
IF CSTR({Customer.customer_Town}) ="" THEN "" ELSE CHR(13) & CSTR({Customer.customer_Town}) &
IF CSTR({Areas.area_Name}) ="" THEN "" ELSE CHR(13) & CSTR({Areas.area_Name}) &
IF CSTR({Customer.customer_Postcode}) ="" then "" ELSE CHR(13) & CSTR({Customer.customer_Postcode})
0
Comment
Question by:mco32
  • 2
  • 2
4 Comments
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 26099870
It is probably NULL not ""

If that isn't the problem then it is the way the IF executes.
The way you have it setup, the Else is the rest of the statement so as soon as one of the ifs is true you will get nothing else.

I would do it this way
Local StringVar outString;

outString := CSTR({Customer.customer_Add1});
IF CSTR({Customer.customer_Add2}) <> "" THEN
     outString := CHR(13) & CSTR({Customer.customer_Add2});
IF CSTR({Customer.customer_Add3}) <> "" THEN
     outString := CHR(13) & CSTR({Customer.customer_Add3}) ;
IF CSTR({Customer.customer_Town}) <> "" THEN
     outString := CHR(13) & CSTR({Customer.customer_Town});
IF CSTR({Areas.area_Name}) <> "" THEN
     outString := CHR(13) & CSTR({Areas.area_Name}) ;
IF CSTR({Customer.customer_Postcode}) <> "" then
     outString := CHR(13) & CSTR({Customer.customer_Postcode});
outString

mlmcc
0
 

Author Closing Comment

by:mco32
ID: 31668693
Slight change and it worked perfectly
Thank you so much

Local StringVar outString;

outString := CSTR({Customer.customer_Add1});
IF CSTR({Customer.customer_Add2}) <> "" THEN
     outString := outString & CHR(13) & CSTR({Customer.customer_Add2});
IF CSTR({Customer.customer_Add3}) <> "" THEN
     outString := outString & CHR(13) & CSTR({Customer.customer_Add3}) ;
IF CSTR({Customer.customer_Town}) <> "" THEN
     outString := outString & CHR(13) & CSTR({Customer.customer_Town});
IF CSTR({Areas.area_Name}) <> "" THEN
     outString := outString & CHR(13) & CSTR({Areas.area_Name}) ;
IF CSTR({Customer.customer_Postcode}) <> "" then
     outString := outString & CHR(13) & CSTR({Customer.customer_Postcode});
outString
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 26100320
Good catch.  That is the problem with not being able to run the code.

mlmcc
0
 

Author Comment

by:mco32
ID: 26103716
Thank you again - never would have got this without you
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question