Solved

crystal reports check null and concatenate string

Posted on 2013-05-29
5
2,590 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 101

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 101

Expert Comment

by:mlmcc
ID: 39204913
There is but no problem

mlmcc
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

631 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