pgkdavefdd
asked on
Formula Field for Address Label
I am trying to write a formula field that would display one address line if only Address Line One has value assigned in the database and two address lines if both address lines have values.
Here is the code I am using but it does not display the 2nd address:
dim x as string
if len({CWVMembers.Addr2})>3 then
x = trim({CWVMembers.Addr1}) + Chr(13)+ {CWVMembers.Addr2}
elseif isnull({CWVMembers.Addr2}) = true then
x = trim({CWVMembers.Addr1})
else
x = trim({CWVMembers.Addr1})
end if
formula = x
Please advise whatI need to do to correct this.
Here is the code I am using but it does not display the 2nd address:
dim x as string
if len({CWVMembers.Addr2})>3 then
x = trim({CWVMembers.Addr1}) + Chr(13)+ {CWVMembers.Addr2}
elseif isnull({CWVMembers.Addr2})
x = trim({CWVMembers.Addr1})
else
x = trim({CWVMembers.Addr1})
end if
formula = x
Please advise whatI need to do to correct this.
If field can be NULL then you need to test for the NULL condition first
dim x as string
if isnull({CWVMembers.Addr2}) = true then
x = trim({CWVMembers.Addr1})
else
x = trim({CWVMembers.Addr1}) + Chr(13)+ {CWVMembers.Addr2}
end if
formula = x
mlmcc
dim x as string
if isnull({CWVMembers.Addr2})
x = trim({CWVMembers.Addr1})
else
x = trim({CWVMembers.Addr1}) + Chr(13)+ {CWVMembers.Addr2}
end if
formula = x
mlmcc
using fields from your datasource definition
stringVar varAddress1:={CWVMembers.A ddr1} ;
stringVar varAddress2:={CWVMembers.A ddr2};
if varAddress2=chr(0) then
varAddress2:=""
else
varAddress2:=trim(varAddre ss2);
if len(varAddress2)>0 then
varAddress2:=chr(13) + varAddress2;
varAddress1 + varAddress2;
stringVar varAddress1:={CWVMembers.A
stringVar varAddress2:={CWVMembers.A
if varAddress2=chr(0) then
varAddress2:=""
else
varAddress2:=trim(varAddre
if len(varAddress2)>0 then
varAddress2:=chr(13) + varAddress2;
varAddress1 + varAddress2;
If the field can be NULL the only test that will succeed on it is IsNull. All other tests will fail and the formula will terminate execution. In Crystal NULL is lack of a value not the empty string or the chr(0) string.
mlmcc
mlmcc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This works great! Thansk you for your help!
You're welcome. Glad I could help.
James
James
stringVar varAddress2:=chr(0);
if varAddress2=chr(0) then
varAddress2:=""
else
varAddress2:=trim(varAddre
if len(varAddress2)>0 then
varAddress2:=chr(13) + varAddress2;
varAddress1 + varAddress2;