Link to home
Start Free TrialLog in
Avatar of lanier3532
lanier3532

asked on

set variables in Crystal Reports XI

I have a report with several groups:
---> Order Type
----------> Ship Date
---------------->Order Number
---------------------> Model Number
----------------------------Detail Row

i want to use the "Supress if repeated" option on the OrderQty at the detail level, but it also supresses the OrderQty of the previous or next order if the OrderQty is the same.  I only need to supress it if the OrderNumber and Model number repeat.

i have created Global vars in a formula and placed in the Report Header:
global stringvar ProjNum;
global stringvar ModelNum;

Then in the Model Number footer:
Global stringvar ModelNum;
evaluateafter ({@detOrderQty});
ModelNum={order_details.ProductName}

In the Order Number footer:
global stringvar ProjNum;
evaluateafter ({@detModelNum});
ProjNum={Orders.ProjectNumber}

and finally in the Detail Line:
Global stringvar ProjNum;
global stringvar ModelNum;
whilereadingrecords;
if ProjNum={Orders.ProjectNumber}
    and ModelNum={order_details.ProductName} then
0
else
{order_details.Quantity}

My assumption was that the group footers would set the global vars and if the current record didn't match the ProjNum and the ModelNum, they would return the OrderQty, else return 0.

Help is appreciated,
Harold
Avatar of Mike McCracken
Mike McCracken

Add WhilePrintingRecords to each formula as the first line

Crystal evaluates formulas when it "can" so in this case they are being evaluated in an early pass through the report and values for variables don't get saved.

mlmcc
Avatar of lanier3532

ASKER

i put the "WhilePrintingRecords;" as the 1st line of each formula.
no success.
When i have an order with the same Model#, but different ShipTo locations, it still repeats the OrderQty even though the ProjectNumber (OrderNumber) and the ModelNumber are the same.
Can you upload the report?

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of James0628
James0628

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, i wanted to use the "Suppress if Duplicated" option.  The formulas were a terrible way to do what you elegantly accomplished using the "Previous" reference.  I removed the formulas and used the "Previous" code and all is well.

Thanks again,
Harold
You're welcome.  Glad I could help.

 FWIW, I'm not sure why your formulas didn't work.  It seemed like they should.  It did occur to me that the EvaluateAfter functions might be a problem.  Specifically, one of your formulas used evaluateafter ({@detOrderQty}).  If {@detOrderQty} was your last formula (that was checking the variables and producing {order_details.Quantity} or 0), maybe that EvaluateAfter was forcing {@detOrderQty} to be evaluated at the wrong time.

 James