Passing Parameters to a Crystal Report with a Subreport

C

cdmunoz

I've created a report that summarizes a client's record, but then has a
subreport attached that gives historical information.

Okay, here's the issue. I can call this report and pass it the parameters
needed through my .NET program and it works great if only 1 client is
selected. However, if multiple clients are selected then the subreport will
list every historical record for every client selected on each client's
summary report.

On the report: under the subreport links - I have the checkbox "Select data
in subreport based on field" checked. In the subreport - the parameter field
is set to allow "Multiple values" and "Discrete values".

In the program - I'm loading an array with each parameter value that's
selected from the main report (each client's id) and then I'm setting the
report's parameter value to that array.

Here's a snippet of the code:
For Each lRow As DataRow In DataSet.Rows 'Main report's dataset
Dim lpdvValue As ParameterDiscreteValue = New ParameterDiscreteValue

lpdvValue.Value = lRow("ID").ToString

CurrentParameterValues.Add(lpdvValue)

ParameterArray.Add(lpdvValue)
Next

'*** then after loading the main report...

If SubReportFlag Then 'Denotes whether a subreport is attached to the
report.
Dim lpfdDefinitions As ParameterFieldDefinitions =
objectReport.DataDefinition.ParameterFields
Dim lpfdDefinition As ParameterFieldDefinition =
lpfdDefinitions(ParameterName)

lpfdDefinition.ApplyCurrentValues(CurrentParameterValues)


objectReport.OpenSubreport(SubReportName).SetDataSource(subreportdataset)
objectReport.SetParameterValue(ParameterName,
ParameterArray.ToArray(), SubReportName)
End If

As stated previously, it works fine if the user selects 1 client, but not
with multiple clients....what am I missing?
 
M

marklar20

I've created areportthat summarizes a client's record, but then has a
subreport attached that gives historical information.

Okay, here's the issue.  I can call thisreportand pass it the parameters
needed through my .NET program and it works great if only 1 client is
selected.  However, if multiple clients are selected then the subreport will
list every historical record for every client selected on each client's
summaryreport.

On thereport:  under the subreport links - I have the checkbox "Select data
in subreport based on field" checked.  In the subreport - the parameter field
is set to allow "Multiple values" and "Discrete values".

In the program - I'm loading an array with each parameter value that's
selected from the mainreport(each client's id) and then I'm setting thereport'sparameter value to that array.

Here's a snippet of the code:
For Each lRow As DataRow In DataSet.Rows   'Mainreport'sdataset
      Dim lpdvValue As ParameterDiscreteValue = New ParameterDiscreteValue

      lpdvValue.Value = lRow("ID").ToString

      CurrentParameterValues.Add(lpdvValue)

      ParameterArray.Add(lpdvValue)
Next

'*** then after loading the mainreport...

If SubReportFlag Then       'Denotes whether a subreport is attachedto thereport.
      Dim lpfdDefinitions As ParameterFieldDefinitions =
objectReport.DataDefinition.ParameterFields
      Dim lpfdDefinition As ParameterFieldDefinition =
lpfdDefinitions(ParameterName)

      lpfdDefinition.ApplyCurrentValues(CurrentParameterValues)

objectReport.OpenSubreport(SubReportName).SetDataSource(subreportdataset)
      objectReport.SetParameterValue(ParameterName,
ParameterArray.ToArray(), SubReportName)
End If

As stated previously, it works fine if the user selects 1 client, but not
with multiple clients....what am I missing?

I'm having the same issue. Except mine is specific transaction data
for multiple accounts. My thinking is that there are multiple
sub reports based on the grouping of the data. I am not sure though.
I'll fill you in when I figure it out myself :/
 
C

cdmunoz

For those of you who have the same issue, I have resolved my problem. The
following is what I did to get the parameters to pass to the subreport
correctly.

Within the subroutine that I get each parameter for each subreport:

For Each lSubreport As SubreportItems In mcolSubreports.Values
Dim crSubReportDoc As ReportDocument

crSubReportDoc = mobjReport.OpenSubreport(lSubreport.SubName)
crSubReportDoc.SetDataSource(lSubreport.DataTable)

Dim lpfdDefinitions As ParameterFieldDefinitions =
crSubReportDoc.DataDefinition.ParameterFields
Dim lpfdDefinition As ParameterFieldDefinition =
lpfdDefinitions.Item("PM-" & lSubreport.ParaName)

For Each lRow As DataRow In mobjData.Rows '// I actually had to move
this routine here for it to pass the all the values correctly.
Dim lpdvValue As ParameterDiscreteValue = New
ParameterDiscreteValue

lpdvValue.Value = lRow("adID").ToString

lpfdDefinition.CurrentValues.Add(lpdvValue)

lSubreport.Values.Add(lpdvValue)
Next

lpfdDefinition.ApplyCurrentValues(lpfdDefinition.CurrentValues)

mobjReport.SetParameterValue("PM-" & lSubreport.ParaName,
lpfdDefinition.CurrentValues.ToArray(), lSubreport.SubName)

Next

This works great and I get the correct record linking the subreport with the
main report.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top