Crystal reports, sub-reports, and shared variables

49,771

Solution 1

The problem is that @InitVars is in the page header, not the report header. It is resetting the variable to 0 at the top of every page.

Moving @InitVars to the report header fixed it so the correct number comes up in the sub-report in Details az.

I still see some odd behavior when I include the variable in the main report, but since that was just for debugging, not the main target, I don't care.

Solution 2

I have a vague memory that I'm now having a hard time substantiating about shared variables not passing back up from a subreport. Still looking; good thing it's Friday afternoon.

Edit: I can't find what I was looking for, so a general thought. Check evaluation time, and make sure that the later section on the main report is evaluating after the subreport (WhilePrintingRecords might be your friend here).

Share:
49,771
LeBleu
Author by

LeBleu

Updated on February 01, 2020

Comments

  • LeBleu
    LeBleu about 4 years

    I have a formula @InitVars in the page header which includes the following, and similar lines:

    shared numbervar runWaste:=0;
    

    In Details v, I have a sub-report, which has a formula @SetRunWaste:

    shared numbervar runWaste;
    if (OnFirstRecord) then
    (
    if not(isnull({x.x-or})) and 
    not(isnull({x.y-override})) and {x.y-override} = true then
    runWaste:={x.x-or} 
      else
    runWaste:= {x.x}
    );
    runWaste
    

    I can see the output of this formula in the sub-report is 18.00.

    However, both in another sub-report, in Details az, and in the main report in Details w (as a test), I have the following formula @test:

    shared numbervar runWaste;
    runWaste;
    

    In both places, it shows as 0.00.

    Why is it showing 0 not 18?

    I'm using Crystal Reports version 11.0.0.895.