How to share data at main report and sub report, Crystal Report 10?

Hi, Experts
I would like to share some information located at main report with sub report. For example, in main report have quantity, so in my sub report the quantity will be used for some calculation.

How can it be share in sub report or any other ways for me to get the quantity data?

Thank you in advanced....
chkuehAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
You can use shared variables

In the main report report header add a formula

WhilePrintingRecords;
Shared NumberVar Quantity;
''

In the main report set the quantity total
WhilePrintingRecords;
Shared NumberVar Quantity;
Quantity := SomeField};
''

In the subreport after the setting formula
WhilePrintingRecords;
Shared NumberVar Quantity;
Use quantity like any other variable

mlmcc
0
chkuehAuthor Commented:
Hi,

any guide for me to follow? i not really expert in crystal report...thanks
0
mlmccCommented:
Not really.  Just follow the seps I outlined.

To create a new formula right click FORMULAs in the Field Explorer
Click NEW
Give it a name
Enter as shown
Save
Drag to report like any other field

mlmcc
0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

chkuehAuthor Commented:
Hi, mlmcc...

i had create the formula at main report with this formula...---formula = {table1.Qty}--

what should i do at sub report? thank you.
0
PCIIainCommented:
Okay, another way to do this is to add the field to the subreport links.

(Right click the subreport, change subreport links, add the field(s) you're interested in, but untick the bit where it says "select data in subreport based on field")

This will give you a parameter in the subreport which will contain the data from that field at the time the subreport is called. {?Pm-table1.qty} use that in the calculations.
0
PCIIainCommented:
Otherwise, to do what mlmcc says.

First formula (in main report) in Crystal Syntax.
WhilePrintingRecords;
Shared NumberVar Quantity;
Quantity := {table1.qty};
{table1.qty}


Any formulas you want to use this number in in the subreport. Start with :-
WhilePrintingRecords;
Shared NumberVar Quantity;

and then just use Quantity as the number you're interested in. So, E.G.
WhilePrintingRecords;
Shared NumberVar Quantity;
quantity*{subreporttable.price}

to return the value.

If you are used to doing things in basic syntax rather than Crystal syntax, replace the
WhilePrintingRecords;
Shared NumberVar Quantity;

with
WhilePrintingRecords
Shared  Quantity as number

in all the formulas.
0
chkuehAuthor Commented:
Hi, Experts

This is what i need in my report(as attached image).

Hi, PCllain...
When i insert the formula at Formula workshop - formula editor, i get an error such as:-
(i) The remaining text does not appear to be part of the formula
(ii) the special variable 'Formula' must be assigned a value within the formula.

is that different version of crystal report using different formula writing or i insert the wrong code?

Thank you very much.
Regards,
chkueh


concept.JPG
0
mlmccCommented:
Can you show the formula.

You should be writing 3 separate formulas

mlmcc
0
chkuehAuthor Commented:
Hi,

at main report, i create BatchSize formula fields with below formula:-
Formula = {Table1.Qty}

then, i create again another formula field shared_BatchSize is fr me to share BatchSize in my sub report, but i get an error, (A variable name is expected here.)

then i try another formula:-
whileprintingrecords;
shared NumberVar BatchSize;
BatchSize={@BatchSize}

How can i get it for my sub report?

Thank you.


0
PCIIainCommented:
Have you got the formula editor set to Crystal Syntax or Basic Syntax?
Check above the formula for a dropdown with Either crystal syntax or basic Syntax in it.

Crystal syntax version is :-
whileprintingrecords;
shared NumberVar BatchSize;
BatchSize={@BatchSize};
Batchsize

Basic Syntax Version is.
whileprintingrecords
shared  BatchSize as number
BatchSize={@BatchSize}
formula=Batchsize

Then use the top two lines of the relevant syntax in the formula in the subreport and you should get Batchsize set to the number from the main report.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chkuehAuthor Commented:
Hi, PCllain...
thank you for you guide...i never notice the different before for the crystal & basic syntax. Your code work 100%....but 1 problem is the share @BatchSize field at main report must drag to any part of the report, if not the value that i get in sub report will be "0". Now i drag it to any part of the report & hide it...

another question, at sub report how can i suppress the shared field that has been drag into sub report? all other fields will automatic suppress  when no record but the shared field always displayed.

thank you...
0
mlmccCommented:
THe formula in the main report must be before the suubreport.

You can make a minor change to it so that it shows nothing

Crystal syntax version is :-
whileprintingrecords;
shared NumberVar BatchSize;
BatchSize={@BatchSize};
''

Basic Syntax Version is.
whileprintingrecords
shared  BatchSize as number
BatchSize={@BatchSize}
formula=''

The shared variable will be set and can be used but the formula will show nothing on the main report.

For the subreport you can conditionally suppress the field with a formula like
IsNull({SomeFIeld})

mlmcc
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.