Solved

crystal reports check null and concatenate string

Posted on 2013-05-29
5
2,501 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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