Link to home
Start Free TrialLog in
Avatar of cummina
cummina

asked on

Conditionally suppressing a section containing a subreport using EvaluateAfter

Hello experts,

I have a subreport that is set to suppress if blank.  The subreport is in section 1ca, which is also set to suppress if blank.  Even when the subreport is blank, though, section 1ca isn't suppressing - instead, the section displays a blank space that's the same length as the subreport design.  This is resulting in multiple blank pages in my report.

So I decided to do set up a shared variable to suppress section 1ca conditionally.  

In my main report, in section 1bz (above the subreport), I placed a formula field, NumDisplayedFieldsReset:

       Shared NumberVar NumDisplayedFields:= 0

The subreport consists of 60+ sections that each contain one field value.  Each section is suppressed if its field value is null.  I added a formula to each section that looks like this:

        Shared NumberVar NumDisplayedFields;

        If (the field value is not null) Then
             Shared NumberVar NumDisplayedFields := NumDisplayedFields
         Else  
             Shared NumberVar NumDisplayedFields := NumDisplayedFields + 1 ;

        NumDisplayedFields

In the main report, I set the suppression formula on section 1ca to this:

        Shared NumberVar NumDisplayedFields;
        NumDisplayedFields = 0

This didn't work.  I tested it by creating a new formula field called TotalDisplayedFields that retrieves and displays the NumDisplayedFields variable.  When I put TotalDisplayedFields in section 1cb (below the subreport), NumDisplayedFields = 13, as expected.  When I put it in section 1ca with the subreport, NumDisplayedFields = 0.

So I figured that the suppression formula for the section was being evaluated before the subreport was run.  I tried putting TotalDisplayedFields back in section 1cb, where it was equal to 13.  Then I changed the suppression formula on section 1ca to this:

       EvaluateAfter({@TotalDisplayedFields});
       {@TotalDisplayedFields} = 0

This didn't work - now the TotalDisplayedFields formula in section 1cb (AFTER the subreport) is displaying as 0!  When I remove the EvaluateAfter statement, then the formula calculates correctly as 13.  Just to see if I could figure out what was happening, I tried creating another new formula, TotalDisplayedFields2, that looks like this:

       EvaluateAfter({@TotalDisplayedFields});
       {@TotalDisplayedFields}

If I put TotalDisplayedFields2 in or before section 1ca, TotalDisplayedFields = 0.  If I put TotalDisplayedFields2 after section 1ca (including page headers that appear after section 1ca is printed and sections that I've inserted between section 1ca and the section containing TotalDisplayedFields), then TotalDisplayedFields = 13.

I'm at a loss here.   Is there any way for me to get this to work, or am I stuck with a bunch of blank pages on my report?

Thanks for any ideas, help or direction you can give me!
Anne
Avatar of Mike McCracken
Mike McCracken

Try this

CHange the reset formula.  I have found that the declration works the first time in but once declared the reset needs to be on another line

Shared NumberVar NumDisplayedFields;
NumDisplayedFields:= 0;

mlmcc
Avatar of cummina

ASKER

I appreciate the reply, mlmcc, but unfortunately that didn't do it.  For this particular report that variable is only ever going to be set once anyway.

But it's a good tip - I'll keep this in mind for when I'm doing other resets!

Thanks-
Anne
Try doing the counting in  the suppression formulas rather than separate formulas

Also I think the counting formula is reversed.

mlmcc
Avatar of cummina

ASKER

No luck.  The suppression formula in the main report still seems to be evaluating before the subreport counts, regardless of whether I'm doing the counting in the subreport suppression formulas or in formula fields placed in the subreport sections.  I don't understand why the EvaluateAfter() function is so wonky - I really thought that would be my solution to this.

Also: Oops, sorry, yes, I did get the counting formulas backwards in my post, but they're fine in the report itself - the counting formulas are actually

        Shared NumberVar NumDisplayedFields;

        If (the field value is null) Then
             Shared NumberVar NumDisplayedFields := NumDisplayedFields
         Else  
             Shared NumberVar NumDisplayedFields := NumDisplayedFields + 1 ;

        NumDisplayedFields

Thanks-
Anne
Try it as

       Shared NumberVar NumDisplayedFields;

        If (the field value is null) Then
             Shared NumberVar NumDisplayedFields := NumDisplayedFields
         Else  
             Shared NumberVar NumDisplayedFields := NumDisplayedFields + 1 ;

         ''

mlmcc
Avatar of cummina

ASKER

Sorry, that didn't work either.

Just curious - what's your reasoning for working on the counting formulas in the subreport?  They work fine and I can pass the shared variable back to the main report.  I just can't seem to get the section suppression formula in the main report to evaluate based on the shared variable after it's passed back from the subreport.
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

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
Avatar of cummina

ASKER

Dang, I was afraid of that.  

I was hoping that EvaluateAfter would force the suppression formula in the main report to evaluate after the subreport was done, and that my problem with EvaluateAfter was something that someone would magically know how to fix.

Thanks for the effort, mlmcc.  I do appreciate it.  At least I've confirmed that it's not just me.

Anne
Sorry it turned out that way.  I thought I had a resolution but I had a bad formula that made it seem like it was working.

EvaluateAfter only works with formulas in the same report not with a subreport.

mlmcc