Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Subreport Variables to Main Rpt Calc Issue Post Reply Post New Topic
Author Message
DaBoujibo
Newbie
Newbie


Joined: 21 Feb 2012
Online Status: Offline
Posts: 28
Quote DaBoujibo Replybullet Topic: Subreport Variables to Main Rpt Calc Issue
     Posted: 24 Aug 2012 at 11:46am

I am having issues with bringing in the totals from my subreport into my main report for calculations in my main report.  Thanks in advance for any help!

BACKGROUND
Both of my reports are grouped by the acct #.  The subreport has my totals (@SubReport_Pmt & @SubReport_Adj) in the group footer.  In the main report, I inserted the subreport into the group footer.  Before I began with the calculations, I wanted to validate that the data was pulling in correctly, so I put the formula @MainFormula_Total into the group footer.  The data is not reflecting on the correct records, yet I have the subreport linking the account # field in both tables. 

Where did I go wrong in my coding?  Or what do I need to add to get it to start at the correct position?  It's almost as if it is displaying before it prints the variable data.

TABLE SAMPLES

Current:
Acct#  SubReport_Pmt    SubReport_Adj    @mainformula_Total
0001       1344.00               0.00                      0.00
0002        966.00                0.00                1344.00
0003        653.00                0.00                  966.00
0004        476.00                0.00                  653.00
0005        417.00                0.00                  476.00

Should Be:
Acct#     SubReport_Pmt    SubReport_Adj    @mainformula_Total
0001        1344.00              0.00                    1344.00
0002        966.00                0.00                      966.00
0003        653.00                0.00                      653.00
0004        476.00                0.00                      476.00
0005        417.00                0.00                      417.00


CODE
Subreport Formulas:

 SubReport_Pmt
 whileprintingrecords;
 SHARED CurrencyVar mytotal:= SUM({SECCHEC.HUPAMT},{@frmAccount#});
 
 SubReport_Adj
 whileprintingrecords;
 SHARED CurrencyVar mytotal2:= SUM({SECCHEC.HUADJ},{@frmAccount#});
 
 SubReport_Total
 whileprintingrecords;
 SHARED CurrencyVar mytotal3:= {@SubReport_Pmt}+{@SubReport_Adj};

Main Report Formulas:

 MainFormula_Pmt
 whileprintingrecords;
 Shared CurrencyVar mytotal;
 mytotal

 MainFormula_Adj
 whileprintingrecords;
 Shared CurrencyVar mytotal2;
 mytotal2
 
 MainFormula_Total
 whileprintingrecords;
 Shared CurrencyVar mytotal3;
 mytotal3

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 27 Aug 2012 at 9:16am
most obvious question since everything appears to be off by 1 line,
 
is the subreport run before or the formula in the group footer?  Could be that the formula is being called before the subreport.
 
just to ensure that things are available, I tend to add an additional section the footer and put any formulas that come from the shared variables there, so that I am sure that the variables are populated.
 
HTH
IP IP Logged
DaBoujibo
Newbie
Newbie


Joined: 21 Feb 2012
Online Status: Offline
Posts: 28
Quote DaBoujibo Replybullet Posted: 28 Aug 2012 at 7:26am
Thanks, Lockwelle.  At first, I was not really sure if the subreport is run before the formula or the other way around.  I took your suggestion about adding an additional section to the footer by splitting the footer into A and B.  When I put the subreport in A, and then my formula in B, it worked correctly.  So I think it was that the formula was running first.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum