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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula with 4 fields sorrow 1

Status
Not open for further replies.

Hoppkins

Technical User
Sep 8, 2003
14
GB
I have a formula where it will have 4 fields and depending on which fields have data it will print semi colons between them.

E.g.

Field 1 ; Field 2 ; Field 3 ; Field 4

But if field 4 was blank it would appear as

Field 1 ; Field 2 ; Field 3

And if field 2 were blank:

Field 1 ; Field 3 ; Field 4

Usually for 2 fields i just use a:

if isnull ({field 1}) then
field2 else
if isnull ({field 2}) then
field1 else
field1+"; "+field2

But with 4 it seems to complicated to do it this way. Is there a better way?

Im using Crystal reports 8.5

Thankyou !
 
Hi,
Not sure it will do what you need but try creating a formula for each field:
Code:
@F1
If Trim({Field1}) = "" or IsNull({Field1}) then
' '          // 1 space, not an empty string

else  
 (If Trim({Field2}) = "" or IsNull({Field2}) then
 trim({Field1})    // do not add the ; if the next field   is NULL or it is the last field we want
  else
 trim({Field1}) + '; ')

Make one like that for each field and then place them next to each other or create a 5th formula to concatenate them:

Code:
@DisplayThem
Trim(@F1) + Trim(@F2) + Trim(@F3) + Trim(@F4)

Give it a try...May need some tweeking, but it should give you ideas of an approach..




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Try this

Code:
stringvar x := "";

if isnull({field1}) then
  x := x
else
  x := {field1};
if isnull({field2}) then
  x := x
else
  x := x + ";" + {Field2};
if isnull({field3}) then
  x := x
else
  x := x + ";" + {field3};
if isnull({field4}) then
  x := x
else
  x := x + ";" + {field4};
if left(x,1) = ";" then
  right(x,length(x)-1)
else
  x

-lw
 
Do a formula field for each field, producing spaces if the value is null. I do this regularly for address lines, which can come from more than one source as well as being blank sometimes.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
Got it working using Turkbears method. Thanks very much for all your feedback guys, very interesting indeed :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top