Results 1 to 3 of 3

Thread: Missing Parameters with subreports

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    137

    Missing Parameters with subreports

    I have a crystal report that contains several subreports. The subreports are called from two parameters that are passed to the main report. Each subreport is linked to the main report's parameter values. I'm using the following code to load the report but I receive the "Missing Parameter Values" error.

    Code:
          Dim crReportDocument As New ReportDocument
                 
    		Dim param1 As String = (Request.QueryString("Value1"))
    		Dim param2 As String = (Request.QueryString("Value2"))
    		crReportDocument.Load("C:\...") ' report location
    		crReportDocument.SetDatabaseLogon("username", "password")
    		crReportDocument.SetParameterValue(0, param1 )
    		crReportDocument.SetParameterValue(1, param2)
    		CrystalReportViewer1.ReportSource = crReportDocument
    		CrystalReportViewer1.DataBind()
    Are the parameters being passed correctly? is there another way to pass the parameters to the subreports?

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Missing Parameters with subreports

    This is the syntax I use from VB6 (if you're using asp make the proper changes)

    References:

    Crystal Reports Viewer Control
    Crystal Reports ActiveX Designer Run Time Library

    Code:
    ' Typical Variable Declarations
    dim crApp as New CRAXDRT.Application
    dim crRept as New CRAXDRT.Report
    dim crParamDefs as CRAXDRT.ParameterFieldDefinitions
    dim crParamDef as CRAXDRT.ParameterFieldDefiniton
    dim crDBTab as CRAXDRT.DatabaseTable
    
    ' Open Report File
    set crRept = crApp.OpenReport("WHATEVER.RPT")
    
    ' Set table locations (because my reports run against multiple servers)
    foreach crDBTab in crRep.Database.Tables
      crDBTab.SetLogonInfo "server name", "database name", "userid", "userpassword"
    next
    
    ' Disable Parameter Prompting for the end user
    crRep.EnableParameterPrompting = FALSE
    
    ' Gather the list of available parameters from the report
    set crParamDefs = crRep.ParameterFields
    
    ' Loop through all parameters in the report by name, filling in the appropriate parameter with the right value
    foreach crParamDef in crParamDefs
      select case crParamDef.ParameterFieldName
        case "SubTitle"
          crParamDef.SetCurrentValue "My Report Subtitle Goes Here"
        case "@BeginDate"
          crParamDef.SetCurrentValue datevalue(txtBeginDate)
        case "@EndDate"
          crParamDef.SetCurrentValue datevalue(txtEndDate)
        case "@IntegerParam"
          crParamDef.SetCurrentValue val(int(txtIntegerParam))
      end select
    next
    crViewer1.ReportSource = crRept
    crViewer1.viewReport
    You can pass any value you want to CR, whether the user typed it or your program generated it in this way.

  3. #3
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Missing Parameters with subreports

    To pass parameters values from main report to subreports, you can use Shared Variables or Link the subreports to main report as explained here

    1. Introduction
    This document describes the steps that will allow nested sub reports to share some or all of the selection parameters of the parent report.

    This document shows reports that will share a date range as their parameters as this is a common link between reports.

    The instructions assume that both the Primary and Sub reports have been completed and that the sub report has been inserted into the footer of the Primary report.
    2. Instructions
    2.1. Set up the Primary Report
    In the primary report, create 2 parameter fields called startdate and
    enddate. You do not have to show these fields in the report.

    These parameters are then shown in the report fields list as ?startdate and ?enddate.

    Then create 2 formulas called startdate and enddate. The startdate formula should only contain the report field value {?startdate} and the enddate formula should only contain the report field value {?enddate}.

    These Formulas are then shown in the report fields list as @startdate and @enddate.

    These formulas are required because you cannot create a subreport
    link based on a parameter field.

    You must then edit the selection criteria for the main report to include the data range. Go to the menu options Report|Edit Selection Formula|Record and enter/include the following record selection criteria:

    {table.datefield} >= {@startdate} and {table.datefield} <= {@enddate}
    2.2. Set up the Sub Report
    Create the same 2 parameter fields and the same 2 formula
    fields in the subreport. These do not have to be on the actual report.
    2.3. Link the Reports
    To link the reports go to the menu options Edit|Subreport Links.
    Select the formula @startdate from the available fields. This will activate field link section at the bottom of the screen. Remove the tick from the checkbox to deactivate this area.

    Repeat with the formula @enddate. Then select OK to close the window.

    Now edit the sub report. The above procedure will have created two parameter fields in the sub report,
    {?Pm-@startdate} and {?Pm-@enddate}. These parameters represent the range value passed from the main report.

    You will now have to edit the record selection formula for the sub report.
    Select Report|Edit Selection Formula|Record from the menu and change the record selection to
    read:
    {table.datefield} >= {?Pm-@startdate} and {table.datefield} <= {?Pm-@enddate}.

    Now, when the report is refreshed, the user will enter in the start and end dates in the main report and these values will populate the record selection formula in the subreport.

    Found in http://www.tek-tips.com/faqs.cfm?fid=1329

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width