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

Parameter from main report to sub report

Status
Not open for further replies.
Jul 21, 2011
28
PK
Crystal 2008

Hi, i'm trying to create a report which will show premium's for a date period selected by the user, but also show the period selected for last year.

I decided to create a main report with the user selected data, and then i'd create a subreport which would show same period last year, linked by the Account Group. I created two parameters in my main report {?Start Date} and {?End Date} and added them to the select like so: {tblTrans.TransDate} in {?Start Date} to {?End Date}

Then in the sub report i created the same parameter fields and on the sub report change links, added the parameter values from the main report and in the field link unselected "Select data in subreport based on field" and just selected the corresponding parameter. Then in my select in the subreport i entered this: {tblTrans.TransDate} in date(year({?Start Date})-1,month({?Start Date}), day({?Start Date})) to date(year({?End Date})-1, month({?Start Date}), day({?Start Date})).

However when i run this in shows the data from the main report and not the subreport. Have i done something incorrect? Or am i going about this totally the wrong way?

Thanks
 
Instead of using the parameters directly to link, I would create formulas that subtract a year and use the formulas to link. There's actually an easier way to subtract a year as well:

DateAdd('yyyy', -1, {?Start Date})

Link on both the start date and end date formulas like you normally would - with "Select data in subreport based on field" checked - then edit the selection formula:

{tblTrans.TransDate} in {?pm-Start Date} to {?pm-End Date}

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
I take it you have made your startdate and enddate parameter date fields?

Try

{tblTrans.TransDate} in dateadd('y',-1,{?Start Date})to dateadd('y',-1,{?End Date})

However you may have to rename the parameters in your subreport to startdatesub and enddatesub as I know I've had issues with particular versions of crystal if your subreport parameters are the same name as your main report parameters and then you'd need to amend the selection.

Let me know how you get on. Hope it helps

Annette
 
Thank you Annette, that worked perfectly, although i changed the dateadd to say ('yyyy',-1,{?Start Date}).

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top