Crystal Report 10 Formula not working?
I'm using CR 10. I have a report that has a simple formula that formats a customers address information. The address isn't showing up on the report. The problem is that all the records have data in them except for some of the Address2 and Address3 data fields. I've tried dropping the individual Contact fields onto the report and it works fine. Here is the formula below.
Code:
Dim strformula as String
if {AR_Customer.CustomerName} <> "" then
strformula = {AR_Customer.CustomerName} & chr(13) + chr(10)
end if
if {AR_Customer.AddressLine1} <> "" then
strformula = strformula & {AR_Customer.AddressLine1} & chr(13) + chr(10)
end if
if {AR_Customer.AddressLine2} <> "" then
strformula = strformula & {AR_Customer.AddressLine2} & chr(13) + chr(10)
end if
if {AR_Customer.AddressLine3} <> "" then
strformula = strformula & {AR_Customer.AddressLine3} & chr(13) + chr(10)
end if
if {AR_Customer.City} <> "" then
strformula = strformula & {AR_Customer.City} & ", "
end if
if {AR_Customer.State} <> "" then
strformula = strformula & {AR_Customer.State} & " "
end if
if {AR_Customer.ZipCode} <> "" then
strformula = strformula & {AR_Customer.ZipCode}
end if
formula = strformula
What am I doing wrong. I'm using Basic Syntax for all my formulas.
Thanks,
Re: Crystal Report 10 Formula not working?
If any one of the database fields contains a Null then the result of the formula will be Null.
Either use the IsNull function on each line that could possibly contain a Null
Code:
if Not IsNull({AR_Customer.AddressLine2}) And {AR_Customer.AddressLine2} <> "" then
strformula = strformula & {AR_Customer.AddressLine2} & chr(13) + chr(10)
end if
Or have CR convert ALL Nulls to a default value by setting the option Convert Null Field Value to Default (File\Report Options menu). Note the Perform Grouping On Server option must be off in order for this option to be enabled.
Re: Crystal Report 10 Formula not working?
Bruce,
That worked!!! I just saw something that I didn't do and that was change the "or" to "and" for a compound statement. After doing that, it worked fine!!!
Thanks for your help!