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

Suppress Blank Fields 2

Status
Not open for further replies.

acr1

Programmer
Oct 12, 2001
73
NZ
Team
I have 4 text fields which are displayed down the page, some of which will be blank on occasion. How do I suppress blank fields to tidy the report. I had thought of concatenation but want the fields displayed DOWN the page so it would require a forced ASCII carriage return.....of sorts for each field. (example being Address1,Address2,Address3, Address4). I am using Seagate Info Vs7.
TIA
Angus





 
Team
I found some of Jim Broadbents' code here that has worked but I still have a blank field in Property Address....even using 'trim'...
Any thoughts...please
Angus


WhilePrintingRecords;
StringVar result := "";

if not isnull({Query.PROPERTY_ADDRESS}) and
length(trim ({Query.PROPERTY_ADDRESS})) <> 0 then
result := result + {Query.PROPERTY_ADDRESS};

if not isnull({Query.STREET_DESCRIPTION}) and
length({Query.STREET_DESCRIPTION}) <> 0 then
result := result + chr(13) + chr(10) +
{Query.STREET_DESCRIPTION};

if not isnull({Query.LOCALITY_NAME}) and
length({Query.LOCALITY_NAME}) <> 0 then
result := result + chr(13) + chr(10) +
{Query.LOCALITY_NAME};

if not isnull({Query.TOWN_NAME}) and
length({Query.TOWN_NAME}) <> 0 then
result := result + chr(13) + chr(10) +
{Query.TOWN_NAME};
result;
 
Is it an address that you are doing...what your problem is you are leaving ugly blank spots on your page..right.

Well let us pretend it is an address since the principles are the same for any similar situation.

We have 4 fields:

{Table.Address1}, {Table.Address2},
{Table.City}, {Table.Province} [I'm from Canada :)]

One approach would be to place each field in a separate section and have Section expert option &quot;Suppress Balnk Section&quot; enabled for each section.

Sometimes this approach is fine but I don't like it too much since it restricts what you can put beside these fields since if they are not blank at the same time...you still have the ugly spaces.


So I would create a formula of these 4 fields...like this

@Address

WhilePrintingRecords;
stringVar result := &quot;&quot;;

if not isnull({Table.Address1}) and
length(trim({Table.Address1})) <> 0 then
result := result + {Table.Address1};

if not isnull({Table.Address2}) and
length(trim({Table.Address2})) <> 0 then
result := result + chr(13)+ chr(10)+ {Table.Address2};

if not isnull({Table.City}) and
length(trim({Table.City})) <> 0 then
result := result + chr(13)+ chr(10)+ {Table.City};

if not isnull({Table.Province}) and
length(trim({Table.Province})) <> 0 then
(
if not isnull({Table.City}) then
result := result + &quot;, &quot; + {Table.Province}
else
result := result + chr(13)+ chr(10)+
{Table.Province}
);

result;


the last &quot;if block&quot; is to place the place the Province next to the city if the city was not null otherwise it comes below the address line

so the results would look like this for 2 examples:

Suite 100 Suite 100
123 Pleasant St. OR 123 Pleasant St.
Anywhere, Alberta Alberta

Now this field is placed in a section with the &quot;Can Grow&quot; for the field enabled. If you place this at the bottom of a section then the section will expand without overwriting anything underneath.

Hope this helps Jim Broadbent
 
Jim
Thanks for the reply. Had commented on your code in a previous post here...TIA.

Problem is the first field when blank I want to suppress.
Trim does not appear to work.
Angus
 
Another approach is to put the fields into a text box (on seperate lines) and set &quot;Supress Embedded Blank Field&quot; under Format Field.

To use this feature, the field has to be on a line by itself and must be null or blank. Editor and Publisher of Crystal Clear
 
Chelseatech, I never noticed that property before. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
I don't like using the &quot;embedded&quot; field - in - Textbox approach...there can be some severe hits on performance....especially if you drop a formula field into the textbox. Jim Broadbent
 
Acr1 -

I see the problem.....

WhilePrintingRecords;
StringVar result := &quot;&quot;;

if not isnull({Query.PROPERTY_ADDRESS}) and
length(trim ({Query.PROPERTY_ADDRESS})) <> 0 then
result := result + {Query.PROPERTY_ADDRESS};

if not isnull({Query.STREET_DESCRIPTION}) and
length({Query.STREET_DESCRIPTION}) <> 0 then
result := result + chr(13) + chr(10) +
{Query.STREET_DESCRIPTION};

It IS catching the null/blank value for {Query.PROPERTY_ADDRESS} but if you notice the second line automatically adds a carriage return...this is sloppiness on my part I suppose.....99times / 100 is the address line is blank then it is the second line that is the problem. You can increase the bullet proofing of this by using the following

WhilePrintingRecords;
StringVar result := &quot;&quot;;

if not isnull({Query.PROPERTY_ADDRESS}) and
length(trim ({Query.PROPERTY_ADDRESS})) <> 0 then
result := result + {Query.PROPERTY_ADDRESS};

if not isnull({Query.STREET_DESCRIPTION}) and
length({Query.STREET_DESCRIPTION}) <> 0 then
(
If not isnull({Query.PROPERTY_ADDRESS}) then
result := result + chr(13) + chr(10) +
{Query.STREET_DESCRIPTION}
else
result := result + {Query.STREET_DESCRIPTION};

);


Now it should work for you the way it is supposed to. Jim Broadbent
 

Team
Am impressed with your constructive help and support here; and Jim thanks once again.
Angus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top