views:

3523

answers:

7

I'm creating a invoice crystal report for sage mas 500 AR module. In it, I'm attempting to add the tarinvoice.balance field with the following formula:

if {tarPrintInvcHdrWrk.Posted} = 1 then 
    ToText({tarInvoice.Balance})

I'm assuming that when the {tarPrintInvcHdrWrk.Posted} = 1 conditional statement holds FALSE, it doesn't attempt to pull the invoice field because when I remove the formula from the report, the form displays correctly without it.

When the conditional statement renders true in the report, the balance fields behaves correctly. However, with the formula renders FALSE in the CR form, the entire crystal report bombs and displays blank. Any ideas why or what i'm doing wrong?

thanks in advance

+1  A: 

I believe the conditional statement fails immediately if you encounter a NULL, so your formula needs to test IsNull({tarPrintInvcHdrWrk.Posted}) before it tests equality with "1".

micahwittman
A: 

You can change the way Crystal handles a null value for a value in a formula. At the top of the Formula Workshop there is a drop down box that usually says "Exceptions For Nulls".
Change this to the other option "Default Values For Nulls" and your formula should no longer bomb out. You used to be able to specify the what the default values applied were, but more recent versions of Crystal have these hard coded. Search the help for "Null Treatment" for a table showing them.

Anthony K
I tried changing it to Default Values for Nulls and the report still bombs. thanks for the tip. I could see how that would help on future issues.
A: 

I modified the formula to this:

if isnull({tarPrintInvcHdrWrk.Posted}) = FALSE then 
    if {tarPrintInvcHdrWrk.Posted} = 1 then 
        if isnull({tarInvoice.Balance}) = FALSE then 
            ToText({tarInvoice.Balance})
        else 
            "0.00" 
    else 
        "0.0"
else 
"0"

The crystal report still bombs.. Nevertheless, it does show "0" in the appropriate space.

A: 

I saw a suggestion on Exp.Exch to try putting the field into a variable before converting it to text.
e.g.

NumberVar InvoiceBalance;  
If isnull({tarInvoice.Balance}) then
    InvoiceBalance := 0
Else
    InvoiceBalance := {tarInvoice.Balance};

If {tarPrintInvcHdrWrk.Posted} = 1 then
    ToText(InvoiceBalance);

I also tried to recreate your problem, since I have see similar things before.
No luck though trying with CR 8.5 & XI R2. Perhpas it has to do with linked tables as well, since I only tried on a simple single table.
I have also seen similar behaviour when using a formula within a Running Total - they do not like nulls at all!

Anthony K
A: 

Just tried setting everything to zero and the report still bombs. I'm starting to think its more of a query error in the report. I wish there was a way to exclude the field in the query when posted = 0.

With tarinvoice.balance removed when the posted = 0, the report works fine.
With tarinvoice.balance included and posted = 1, report works fine.

With tarinvoice.balance included and posted =0, report bombs.

A: 

If you put {tarInvoice.Balance} directly on report (into details "debug" section - often needed, don't forget supress it in production :)), what values it displays or does report become empty?

Arvo
A: 

Maybe you have Suppress If Blank section on your report. Try to put: Else " "

Michael Buen