Hide a field if it has no data in Crystal Reports

If I have:
Name
Address1
Address2
City

and want to hide the "Address2" Database field if it is empty, like:
Name
Address1
City

how can I do that?
I'm using Visual Studio 2005 crystal reports.  thanks
LVL 16
MikeMCSDAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kenwagersCommented:
Put each field in a different detail band, and then select "Suppress Blank Section" under the section expert.

To create separate detail bands, right click on the left side of the design window in the 'D' band, and select "Insert Section Below".
0
MikeMCSDAuthor Commented:
thanks ken, . .

so something like this:

Details C (Section 6)
Name
Address1
City

Details D  "Suppress"
Address2

Details E
City
0
kenwagersCommented:
I think you have it.  Visually in the designer, it's more like:

--------------------------------
Da -->  Name
--------------------------------
Db -->  Address1
--------------------------------
Dc -->   Address1
--------------------------------
Dd -->  City
--------------------------------

Then, mark each of the Sections in the Section Expert as "Suppress Blank Section"

(my example has many, many Detail bands).
SectionExpert.jpg
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

MikeMCSDAuthor Commented:
perfect, thank you
0
mlmccCommented:
That is one method.  Another involves using a formula and testing each field in turn

WhilePrintingRecords;
Local StringVar dispString;

If Not IsNull({Field1}) then
    dispString := {Field1} & chr(13);

If Not IsNull({Field2}) then
    dispString := {Field2} & chr(13);

If Not IsNull({Field3}) then
etc

Left(dispString,Length(dispString)-1)

mlmcc    
0
kenwagersCommented:
But will that suppress the line?  The other method I use is somewhat more involved, but nice if you're doing it in many reports.

use this formula in the report:

ColsToRows({Command.Name},{Command.street_1},
{Command.street_2},{Command.street_3},
{Command.city}+' '+{Command.state}+'  '+{Command.zip})

After creating the "ColsToRows" function in the Crystal Repository:

Function ColsToRows(optional field1 as String = "", optional field2 as String = "", optional field3 as String = "", optional field4 as String = "", optional field5 as String = "", optional field6 as String = "", optional field7 as String = "", optional field8 as String = "", optional field9 as String = "", optional field10 as String = "")
    dim I as number
    dim hold as string

    If not(Trim(field1) in Array(",","")) Then hold = hold + field1 + chr(13)
    If not(Trim(field2) in Array(",","")) Then hold = hold + field2 + chr(13)
    If not(Trim(field3) in Array(",","")) Then hold = hold + field3 + chr(13)
    If not(Trim(field4) in Array(",","")) Then hold = hold + field4 + chr(13)
    If not(Trim(field5) in Array(",","")) Then hold = hold + field5 + chr(13)
    If not(Trim(field6) in Array(",","")) Then hold = hold + field6 + chr(13)
    If not(Trim(field7) in Array(",","")) Then hold = hold + field7 + chr(13)
    If not(Trim(field8) in Array(",","")) Then hold = hold + field8 + chr(13)
    If not(Trim(field9) in Array(",","")) Then hold = hold + field9 + chr(13)
    If not(Trim(field10) in Array(",","")) Then hold = hold + field10 + chr(13)

    ColsToRows = hold
End Function
0
kenwagersCommented:
mlmcc, I see your logic now.  Your method will also suppress the line.  Nice solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.