Click to See Complete Forum and Search --> : not accessing values from subreport to main report


gazala
May 23rd, 2007, 01:03 PM
I need two values from 2 subreports,so i created formula on each with shared variables as:

1) shared numbervar usagehours := {Command.HRS}

2) Another subreport variable as,

shared numbervar nextduehours := {Command.HRS}

In main report i write a formula as:

whileprintingrecords;

Shared numbervar usagehours;
Shared numbervar nextduehours;

usagehours - nextduehours

but displaying 0 on report.

(I am using formula on main report after the subreports (subreports are being displayed as columns) so formula is the third column.)

SvB_NY
May 23rd, 2007, 04:19 PM
Actually, you need to write 2 more formulas to reset your variables and place each of the formulas in PH section of the appropriate subreport:

1. @reset_usagehours
shared numbervar usagehours:=0

2. @reset_nextduehours
shared numbervar nextduehours:=0

JaganEllis
May 23rd, 2007, 04:47 PM
Are these subreports in the details section? Is it only the first record that has this problem? Are following records displaying the previous record's calculation result?
It's probably because they are all in the same section and the formula is being run 'before' the subreports.

gazala
May 24th, 2007, 01:21 PM
i tried by reseting the variables to 0 but its not working.

Yes,the subreport and formula columns are all in same section,but i tried keeping formula in different section,even then its displaying 0.Any more ideas?

SvB_NY
May 24th, 2007, 05:37 PM
In the main report, place the formula(s) with your variables under the section which containes the subreports.
For example, if your subreports are in your Details, insert a section below (so you would have Da and Db) and place that formula(s) in your Db section.

gazala
May 25th, 2007, 08:54 AM
Still displaying 0 .
Writing the whole process again:

1) Created two formulas in each subreports, one for setting the variable value i.e
Shared numbervar usagehours := {command.hrs}
another for reseting it to 0 i.e

Shared numbervar usagehours := 0
Place the reset formula in page header section.

2) Created a calculation formula in main report ,thats using both of these shared variables i.e

whileprintingrecords;

Shared numbervar usagehours ;
Shared numbervar nextduehours;

usagehours - nextduehours

3) Place this formula under the section below the subreport.But still displaying 0.

JaganEllis
May 26th, 2007, 05:46 AM
What are the values of usagehours and nextduehours? Either they're the same, hence the 0 result, or the subreports are not setting the values as you're expecting. Try temporarily unsuppressing the formula/section in the subreports to see the values.
Also make sure that you've got the whileprintingrecords line in all formulas that need it. e.g. you've not mentioned it in (2) above, but that could just be 'cos you didn't think you needed to rather than because it's not there.

And why bother with the 'Shared numbervar usagehours := 0' formula in the subreport's page header if you are setting it later in the subreport anyway? Either the subreport will have a record and set the value to command.hours, or there'll be no records in the subreport so the formula to set it to 0 in the page header won't run and it'll retain its value from the previous call to the subreport.
i.e. if you know that the subreport will always have a record then there's no need to initialise the variable 'cos you're going to set it anyway; and if the subreport may have a record then you'll need to do the initialisation in the main report, before the subreport is run.

gazala
May 28th, 2007, 03:03 PM
Thank you all who helped and guide.
I just tried something and it worked,so wanna share.

I just created 3rd subreport and create the calculation formula inside that report and place the subreport after previous 2,and its diplaying result.
Creating a subreport is useful in a way if you want to display value at same level as was in my case (i needed the result beside the usage hours and next due hours,not below them)

Thanks again,will be there soon with new problem :-)