Crystal Reports – Passing parameter values from main to subreport

Test Environment: Crystal Reports Basic for Visual Studio 2008

Steps:

  1. Create Main Report [Eg:myMainReport.rpt]
  2. Create SubReport [Eg:mySubReport.rpt]
  3. Pass parameters [From database/through code] to Main report
  4. Choose which parameter(s) [Eg.{Discount}] you want to pass to Sub Report
  5. Open mySubReport; Create a parameter in the format [Name]:{Pm-?ParameteName} [Eg:{Pm-?Discount}] as normal parameter field; Place this parameter in the app section of the report to display.
  6. Open myMainReport; Select ‘mySubReport.rpt’; Right-Click, Click ‘Re-Import sub report’
  7. Again Right-Click, Click ‘Change sub-report links’
  8. In the new wizard choose ‘Available Fields’; then select ‘Discount’ under ‘Report Fields’; Drag this to ‘Field(s) to link to’ section
  9. Under ‘?Discount field link’ dropdown list select {?Pm-?Discount}; This will gred-out ‘Select data in subreport based on field’ tick box and also its dropdown list,Finally click OK.
  10. Done & Run to Check