Solved

crystal reports check null and concatenate string

Posted on 2013-05-29
5
2,385 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
Comment Utility
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
Comment Utility
easy
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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
Comment Utility
thanks for the additional info mlmcc ;o) i would award you the points if I could
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
There is but no problem

mlmcc
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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. …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now