Solved

crystal reports check null and concatenate string

Posted on 2013-05-29
5
2,457 Views
Last Modified: 2013-05-29
Hi

I have a crystal report, (c# 2010) connecting to an access database

The report is displaying a clients address, which I ham trying to show in an unbound field

I have code like this,

{command.title} & " " & {command.fname} & " " & {command.sname} & chrW(13) 
& {command.address1} & chrW(13)
& {command.address2} & chrW(13)
& {command.address3} & chrW(13)
& {command.postcode} & chrW(13)

Open in new window


this works fine until I get a null value

how do I check for a null value and concatenate the fields as above?
0
Comment
Question by:cycledude
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
cycledude earned 0 total points
ID: 39204720
Hope this helps someone

stringVar address := "";

if not(isNull({Command.title}))then
    address := {Command.title};

if not(isNull({Command.fname}))then
    address := address & " " & {Command.fname};

if not(isNull({Command.sname}))then
    address := address & " " & {Command.sname};

address := address & chrW(13);

if not(isNull({Command.tblAppointments.address1}))then
    address := address & {Command.tblAppointments.address1} & chrW(13);

if not(isNull({Command.tblAppointments.address2}))then
    address := address &  {Command.tblAppointments.address2} & chrW(13);

if not(isNull({Command.tblAppointments.address3}))then
    address := address &  {Command.tblAppointments.address3} & chrW(13);

if not(isNull({Command.tblAppointments.postcode})) then
    address := address &  {Command.tblAppointments.postcode} & chrW(13);

address;

Open in new window

0
 

Author Closing Comment

by:cycledude
ID: 39204721
easy
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39204735
There are 3 ways to handle this.

1.  There is an option to convert NULL to default for the entire report.  You can do this if NULL is not meaningful in the report.  In the fill version it is in the FILE --> REPORT OPTIONS

2.  In the formula editor there may be an option to USE DEFAULT FOR NULL rather than EXCEPTION FOR NULL

3.  Change the formula to

Local StringVar strOut;
If Not IsNull({command.title}) then
    strOut := {command.title};

If Not IsNull({command.fname}) then
    strOut := strOut  + " " + {command.fname};

If Not IsNull({command.sname}) then
    strOut := strOut  + " " + {command.sname};

If Not IsNull({command.address1}) then
    strOut := strOut  + chr(13) + {command.address1};

If Not IsNull({command.address2}) then
    strOut := strOut  + chr(13) + {command.address2};

If Not IsNull({command.address3}) then
    strOut := strOut  + chr(13) + {command.address3};

If Not IsNull({command.postcode}) then
    strOut := strOut  + chr(13) + {command.postcode};

Trim(strOut)

Open in new window


mlmcc
0
 

Author Comment

by:cycledude
ID: 39204801
thanks for the additional info mlmcc ;o) i would award you the points if I could
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39204913
There is but no problem

mlmcc
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question