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

Pass variable from sub to main report - no records

Status
Not open for further replies.

mart10

MIS
Nov 2, 2007
394
GB
I am using XI

I want to bring bacjk the result of a subreport so I can do a calculation in main report. In the subreport I have

WhilePrintingrecords;
Shared DateTimeVar RateResetDate := Minimum({EVENTS.action_dt})

In the main report I have

WhilePrintingRecords;
Shared DateTimeVar RateResetDate :=Date(0,0,0) I will get this date and compare with run date to get a number of days so I can then do an interest calculation.

However in main reportthe formula does not bring back records (the subreport does)
 
What you should have in your main report is
Code:
 WhilePrintingRecords;
Shared DateTimeVar RateResetDate := RateResetDate
This will allow the main report to read the value set in the subreport, though only in a section below the one which contains the subreport.

Are you sure you need a subreport? They access the database each time, so if it were possible to find the minimum for a group in the main report, that would run better.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Thanks oversight on my part. yes do need subreport unfortunately.

One issue now is that the data in main report shifts one row down ie subreport show 1/12 2/12 3/12 and main will show blank 1/12 2/12
 
Where have you put the subreport? Are you using Edit > Link to pass the correct month to it?

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
In the subreport I have the detail data supressed and I group by deal no. The deal no has a number of cashlow dates when an interest rate is reset and I need to grab the next reset date in the subreport, feed it back to main report to do calculations

Subreport design is :

The selection criteria to filter out past reset dates is:

({EVENTS.deal_no} = {?Pm-DEALS.DEAL_NO})
and({EVENTS.comments} like "RATE*" and
{EVENTS.deal_no} = {?Pm-DEALS.deal_no} and
{EVENTS.action_dt} > CurrentDate
)

Then I group by deal no and create the following formula in the group (I supress the detail):

WhilePrintingrecords;
Shared DateTimeVar RateResetDate := Minimum({EVENTS.action_dt})

I then drop the subreport into the detail of main report and link by deal no
 
That should work. If you're getting results that make no sense, I suggest doing a test version that shows more of the intermediate results.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
the data works fine but it comes through one record line late as I said earlier. Its as though it is waiting for a record to be processed before it can calculate the value and then brings it in on the NEXT record

Weird, this is driving me crazy. Can anyone help please
 
You must place the subreport physically below the row in which you want it displayed. You mentioned that it is to be on the details line. Create another section on the detail line and place the subreport there (B).
Then in the the details A section expert, select the box 'underlay following sections'

Also, the shared variable formula in the subreport must be placed on the report canvas in order to be passed correctly to the main report.

AND one more thing - both main report and subreport need to have a formula for the one shared variable.... the subreport creates it and the main report retrieves it.
 
sorry but this has made no difference and I have followed all your instructions to the letter

It is still out of alignment
 
it is like this now


detail a field1 field 2 variable (from subreport)
detail b subreport

as you suggested with formula for shared variable etc all as above

my results are:

field1 field2 variable
xxx yyy
xxx1 yyy1 zzz
xxx2 yyy2 zzz1
xxx3 yyy3 zzz2

I would expect to see

field1 field2 variable
xxx yyy zzz
xxx1 yyy1 zzz1
xxx2 yyy2 zzz2
xxx3 yyy3 zzz3

I get a blank in first row and then the shift down of the variable I am trying o bring in

I am going crazy!
 
Swap the detail sections

detail a subreport
detail b field1 field 2 variable (from subreport)
 
At first this didnt work but I forgot to change which section had the underlay following sections on (I was lazy and just moved the sections not the fields)

And now it works ! Thankyou RoMarcus for identifying how to fix and ksdid for pointing mix up between A and B sections for subreport holder

I have 2 Crystal manuals 3 inches thick. They show how to pass variables but NOT creating 2 sections or the Underlay issue. I can now use this on another complex report I have

Thank you so much to both of you I was beginning to give up . I have never used Underlay before, I wondered what it did
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top