• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

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
0
MikeMCSD
Asked:
MikeMCSD
  • 4
  • 2
1 Solution
 
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now