Formula field in Crystal Reports - Error

I have a formula field in crystal reports.  In this formula field I have the code:

NumberVar Length_of_Last2;
Length_of_Last2 := Length({vwPullAllActiveChildOther.LastName});
IF RIGHT({vwPullAllActiveChildOther.HouseHold},Length_of_Last2) = {vwPullAllActiveChildOther.LastName} THEN
   {vwPullAllActiveChildOther.FirstName}
ELSE
   {vwPullAllActiveChildOther.FirstName} + " " + {vwPullAllActiveChildOther.LastName};

Open in new window


 I have two views linked together in crystal reports.  In some cases though, there may not be a record in vwPullAllArvieChildOther so if there isn't, I am getting an error in the formula above.  My question is, how can I ignore the formula if now records exist in vwPullAllArchiveChildOther?
jwebster77Asked:
Who is Participating?
 
vastoCommented:
Try this:

if not isnull({vwPullAllActiveChildOther.LastName}) then
(
NumberVar Length_of_Last2;
Length_of_Last2 := Length({vwPullAllActiveChildOther.LastName});
IF RIGHT({vwPullAllActiveChildOther.HouseHold},Length_of_Last2) = {vwPullAllActiveChildOther.LastName} THEN
   {vwPullAllActiveChildOther.FirstName}
ELSE
   {vwPullAllActiveChildOther.FirstName} + " " + {vwPullAllActiveChildOther.LastName};[/b]
)
ELSE
""

Open in new window

0
 
vastoCommented:
Check the value of the field for nulls

if not isnull(vwPullAllArchiveChildOther.LastName) then
 ..... your code here ...
else

default value
0
 
jwebster77Author Commented:
I did as mentioned, see below.  When I run it it says at the last else not part of the code.  (the bolded area is my original code.

if not isnull({vwPullAllActiveChildOther.LastName}) then
[b]NumberVar Length_of_Last2;
Length_of_Last2 := Length({vwPullAllActiveChildOther.LastName});
IF RIGHT({vwPullAllActiveChildOther.HouseHold},Length_of_Last2) = {vwPullAllActiveChildOther.LastName} THEN
   {vwPullAllActiveChildOther.FirstName}
ELSE
   {vwPullAllActiveChildOther.FirstName} + " " + {vwPullAllActiveChildOther.LastName};[/b]
ELSE
0

Open in new window

0
 
mlmccCommented:
What error are you getting in the formula?

mlmcc
0
 
James0628Commented:
FWIW, I'm also wondering what error you were getting.  Nulls do seem like the obvious suspect, but if they're not handled in a formula, it seems like you usually just get incorrect results, rather than an actual error.

 Also, you have 3 different table names in your first post.  The table name includes "Active" in the code, but "Arvie" (probably a typo) and "Archive" in the text.  Both "Active" and "Archive" make sense in the table name, so which table are you actually looking at?  Just checking.


 If you haven't already figured this out, you need to remove the [/ b] from the end of one of the lines in the code in vasto's last post.  You had tried to make some of the code bold, but formatting like that doesn't work in code blocks (they're specifically designed to present things without any formatting), so the bold tags were just left in the text.

 James
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.