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!

Problem with Shared Variables

Status
Not open for further replies.
Jun 14, 2008
16
US
Hello there...

I am using Crystal 8.5 with sql DB. on my main report, i have a SubReport1 in Details a and SubReport2 in Details b. On SubReport2, I create a Shared variable like this:

Code:
whileprintingrecords;
if isnull(Count ({@DateDiff})) then
shared numbervar SharedItems2 :=  shared numbervar SharedItems1
else
shared numbervar SharedItems2 :=  Count ({@DateDiff}) + shared numbervar SharedItems1

When I display it in SubReport2, it displays fine. Now I wanna be able to have this value available in SubReport1 which is in a section above the SubReport2. In the formula below, I wanna be able to replace the stuff after % by the shared numbervar SharedItems2. However the value for SharedItems2 always comes in as zero and it fails saying Division by zero.

Code:
if Sum ({Stats_DataEntry.Items}) > 0 then
    Sum ({Stats_DataEntry.Items}, {@Description}) %  Sum ({Stats_DataEntry.Items}) & "%"
else
    "0%"

So now my doubt is, Can I access a shared variable that is declared in a report placed below the one i wanna use it in. Is it something like trying to use it before its declared or I thot shared variables can be used freely anywhere?

Thanks!
 
Shared variables are only available in a section below the one in which they are established.

-LB
 
Thanks LB...read a lot of your posts abt tht issue here...hmm....so then whats the solution? I finally got the report working with your help, by using subreport linking and shared vars and what not. Just this one is the last issue i gotto deal with, then i can say IAM DONE:)

I need to get a Total value from Subreport2 to use in SubReport1. But ya SubReport2 is below it...any way around it?

Thanks again...Its edged in my brain now:)
 
Switch the detail sections by dragging detail_b to become detail_a and then insert another section detail_c where you share the results from sub2 that is now located in detail_a and reference them in detail_c (or you could insert the sub again in detail_c).

You can suppress all sections within sub2 in detail_a, format the sub itself to "suppress blank subreport", and format the detail_a section to suppress blank section, so that detail_a doesn't even appear in the report, but you can still share variables from it.

-LB
 
Thanks LB...that sounds like a plan...I am playing around with it and notice the section does not get suppressed. Like you said, I rt click on the Details a and Format and choose Suppress(No Drill Down), then I rt click Subreport in tht section and format subreport and below Object format, i chose Supress. Inspite of tht the blank subreport keeps showing up? Any other place I need to check to make sure its not displayed?

Thanks!
 
No, you CANNOT suppress detail_a and you CANNOT suppress the subreport object. You have to suppress all sections WITHIN the subreport, and then in the main report, go to format subreport->subreport tab->check "suppress blank subreport", and then in the section expert of the main report->detail_a->check "suppress blank section".

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top