Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue Preserving Value

Status
Not open for further replies.

fsub

Programmer
Feb 2, 2006
60
US
I'm using CR11 on an Access database. My formula uses a shared variable. When a condition is met, a sum is moved into the variable. The problem is that the previous value is not saved. When it gets to the next record and the condition is not met, zero is moved into the variable. The formula does not contain any code to move zeros.
 
please post the content of your formula.

I would guess it is something like this:
{@sample}
shared numbervar sa;
IF {table.Field}="XYZ" then sa := 99;

if so, add some logic telling the formula to retain the existing value if the condition is not met, so it looks like this:
IF {table.Field}="XYZ" then sa := 99 else sa := sa;
 
I thought that would work too, but didn't. Here's my formula which is basically the same as your sample....

Shared NumberVar VarE;

If {TblJoin.FundExp.FiscalYear} = {?Pm-?CurrFiscalYear} - 1 and {TblJoin.FundExp.Object} > "6200"
Then VarE := VarE + {TblJoin.Budget19}
Else If {TblJoin.FundExp.FiscalYear} = {?Pm-?CurrFiscalYear} - 1 and {TblJoin.FundExp.Object} > "3000" and {TblJoin.FundExp.Object} < "4000"
Then VarE := VarE + {TblJoin.Actual01} + {TblJoin.Actual02} + {TblJoin.Actual03} + {TblJoin.Actual04} + {TblJoin.Actual05} + {TblJoin.Actual06} +
{TblJoin.Actual07} + {TblJoin.Actual08} + {TblJoin.Actual09} + {TblJoin.Actual10} + {TblJoin.Actual11} + {TblJoin.Actual12}
Else VarE := VarE;
 
i don't have crystal in front of me so cannot test my idea, but....
is it possible on of your value fields could be null? crystal will usually just stop processing when it hits a null value unless you have added specific logic to deal with it.
 
I totally agree about the handling of nulls. It can cause unpredictable results. In report options, I've set all null values to default with the same result. I'll try a few more codes on handling nulls. Thanks for the post.
 
I've determined that it's not a null issue. None of the fields contain nulls.
 
i don't know if it will help or not, but try adding 'WhilePrintingRecords' to the first line of the formula.
 
'WhilePrintingRecords' didn't make a difference. It didn't preserve the value.
 
It turned out that I have a formula that initializes the variable in the wrong place. Although this init formula was in the group header, it seems to initialize a variable being evaluated in the detail section. After I removed the init formula, the value is was saved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top