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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incorrect value being returned in a shared variable

Status
Not open for further replies.

SmithyJD

IS-IT--Management
Sep 23, 2004
52
GB
I have the following variables declaration in a subreport

whileprintingrecords;
Shared numberVar myTotal := Sum ({@Free Stock})

In the main report i have
whileprintingrecords;
shared numbervar mytotal;
mytotal

The problem happens when the subreport has no records it as mytotal on the main report has the previous products total in it. Any ideas what I am doing wrong?
 
In a section prior to the one which houses the subreport, use the following formula:

whileprintingrecords;
Shared numberVar myTotal := 0

Otherwise the shared variable will have the last value still set.

You gave no indication as to your report layout so I can't state exactly where to place it, but if the subreport is in a group footer, place this formula in the group header, or right click whichever section the subreport is in and select insert section below, move the subreport to that new section, and place the formula in the original section location.

-k
 
Where is the shared variable being used on the main report? For exampler, if it's in group footer 1, then insert another group footer below (group footer 1b) and reset the shared variable to 0.

Cheers,
-LW
 
What I had was the sub report in details a and the line using the returned value in details.

I tried inserting a new detail line ( I now have abc) moved the sub report to b and looked in the formaular for my total and it showed what p had input how do I set the value you specified on a section as when I changed it it then lost the calculated total in line c

 
You post is a little confusing. If I understand you

Detail a - shared variable set to 0
detail b - subreport shared variable updated to total
detail c - shared variable used for calculation

Post the formula you are useing in Detail C

 
Subreports in details are generally bad news, you might consider using a SQL Expression, it will prove MUCH faster.

I believe that KS demonstrated how you should use the formula, the rules are simple, reset the variable prior to running the subreport, display the variable after running the subreport.

-k
 
The problem I have is how do I change the value of mytotal depending upon which detail level I am at I understand how it works in the sub report but I only seem to be able to have one formular associated with the formular at main report levele no mater which section I click into when I click edit on the formaul it shows the same expression either

whileprintingrecords;
shared numbervar mytotal:= 0
or
WhilePrintingRecords;
Shared CurrencyVar myTotal;
myTotal

which ever i tried to input last
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top