MikeMCSD
asked on
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
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
ASKER
thanks ken, . .
so something like this:
Details C (Section 6)
Name
Address1
City
Details D "Suppress"
Address2
Details E
City
so something like this:
Details C (Section 6)
Name
Address1
City
Details D "Suppress"
Address2
Details E
City
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect, thank you
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(dis pString)-1 )
mlmcc
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(dis
mlmcc
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.s treet_1},
{Command.street_2},{Comman d.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
use this formula in the report:
ColsToRows({Command.Name},
{Command.street_2},{Comman
{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
mlmcc, I see your logic now. Your method will also suppress the line. Nice solution.
To create separate detail bands, right click on the left side of the design window in the 'D' band, and select "Insert Section Below".