Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: Crystal Report Formula Field Problem Post Reply Post New Topic
Page  of 2 Next >>
Author Message
ranigoal
Newbie
Newbie


Joined: 11 Sep 2007
Location: United States
Online Status: Offline
Posts: 12
Quote ranigoal Replybullet Topic: Crystal Report Formula Field Problem
    Posted: 11 Sep 2007 at 12:18pm

I am new to this.

Here is my problem I have columns for city, state, zip code. The problem with that was I could not formatted nicely for example:

Raleigh             , NC 566777

 

Spring Field     , OR 5552222

 

As you can see there are a lot of empty spaces. So I created a Formula field to make it look nice

Example:

Formula1field1: this is the code behind

{command.Mailing City} + ", " + {command.Mailing State/Province} + " " + {command.Mailing Zip/Postal Code};

 

This worked fine but the problem was if I have an empty zip code which is possible it won’t display the city or state. In some other cases I might have the city and the zip code not the state.

 

So for simplicity I changed the code behind the formula field to the following:

 

if ((Not IsNull({command.Mailing City}))and (Not IsNull({command.Mailing State/Province})) and  (IsNull({command.Mailing Zip/Postal Code}))) Then

  addre := {command.Mailing City} + ", " + {command.Mailing State/Province};

 

If ((Not IsNull({command.Mailing City}))and (Not IsNull({command.Mailing State/Province})) and  (Not IsNull({command.Mailing Zip/Postal Code}))) Then

    addre := {command.Mailing City} + ", " + {command.Mailing State/Province} + " " + {command.Mailing Zip/Postal Code};

 

the problem with this it is always executing the last if Statement

 

 

can you help me plz

 



Edited by ranigoal - 11 Sep 2007 at 12:25pm
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 11 Sep 2007 at 12:56pm

Try this lttle solution....

Create a text box, then place your city, state, and zipcode data fields inside it.  That will take of the spacing issues.  So it  should solve your problems and if it does you wont need to deal with the null issues in a formula.
 
 
Regards,
 
John W.
 
IP IP Logged
ranigoal
Newbie
Newbie


Joined: 11 Sep 2007
Location: United States
Online Status: Offline
Posts: 12
Quote ranigoal Replybullet Posted: 11 Sep 2007 at 1:05pm
Thank you for your replay. I don't think i can do that at this point and the reason is, i am using CrystalReport1.rpt to do this. Adding a text object then adding the columns in the text field it will not do anythig for me.
 
Thanks again
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 11 Sep 2007 at 1:12pm

Sorry it wont work for you.

I do this all the time in my Crystal Report designs to resolve the spacing issues between fields you identified in your original post. I am not clear why this will not work your situation.
 
 
Regards,
 
John W.
IP IP Logged
ranigoal
Newbie
Newbie


Joined: 11 Sep 2007
Location: United States
Online Status: Offline
Posts: 12
Quote ranigoal Replybullet Posted: 11 Sep 2007 at 1:21pm

Forgive me I am new to this. Here is what I did I right click on the rtp file then I added a text object then added the three columns and it did not work. I also tried the box object too. Can you guide me through what you suggested?

 

Thank you

 
 
IP IP Logged
ranigoal
Newbie
Newbie


Joined: 11 Sep 2007
Location: United States
Online Status: Offline
Posts: 12
Quote ranigoal Replybullet Posted: 11 Sep 2007 at 1:33pm
how can you creat a text box in Crystal Report
 
thanks
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 12 Sep 2007 at 8:29am

Brian has a very good example in his online book concerning the problem and the solution. It even has pictures. Here is the liink

http://www.crystalreportsbook.com/Crystal_Reports_XI.asp?Page=2_6


Regards,

John W.
www.CustomReportWriters.net

IP IP Logged
wattsjr
Groupie
Groupie
Avatar

Joined: 25 Jun 2007
Location: United States
Online Status: Offline
Posts: 51
Quote wattsjr Replybullet Posted: 12 Sep 2007 at 10:35am
Although the example shown above is quite elegant (I plan to start using it myself), it does assume that you will always have all of the fields populated, or you won't't have any punctuation or labels imbedded in the text string. For example, the "," after the City or "Ext." as part of a phone number. Sometimes, your just stuck with having to use a formula.
 
So, to answer you original question (using your own names), I think that the following formula should work for you:
If IsNull({Mailing Zip/Postal Code})
    Then If IsNull({Mailing State/Province})
            Then (RightTrim({Mailing City})
            Else (RightTrim({Mailing City}) + ", " + (RightTrim({Mailing State/Province})
    Else If IsNull({Mailing State/Province})
            Then RightTrim ({Mailing City}) + " " RightTrim ({Mailing Zip/Postal Code})
            Else RightTrim ({Mailing City}) + ", " + RightTrim ({Mailing State/Province}) + " " RightTrim({Mailing Zip/Postal Code})
 
It assumes that you will always have a city.
 
-jrw
IP IP Logged
ranigoal
Newbie
Newbie


Joined: 11 Sep 2007
Location: United States
Online Status: Offline
Posts: 12
Quote ranigoal Replybullet Posted: 12 Sep 2007 at 10:36am
jkwrpc,
 
Thank you sooo much. This is exactly  what I have been looking for since yesterday, for some reason I was not getting what I searched for in Google. Also thanks a lot for the resource you provided to me. This book is a great resource.

IP IP Logged
ranigoal
Newbie
Newbie


Joined: 11 Sep 2007
Location: United States
Online Status: Offline
Posts: 12
Quote ranigoal Replybullet Posted: 12 Sep 2007 at 11:07am
wattsjr ,
 
Thank you for your input,

I tried what you suggested and it worked, however, the only trick or downside of this is you can’t take out an empty row for example:

 

This is good

 

Mr. Mike Soranto

Director

1411 South St

Raleigh, NC 44444

 

Now if we don’t have the title we will have the following result

 

Mr. Mike Soranto

 

1411 South St

Raleigh, NC 44444

 

*Note an extra row between the name and the address

 

Thanks a lot for your input

IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.