Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Code in vb.net to pass multiple values to parameter fields

I have designed a report in which it has a month parameter which accepts multiple values. Can anyone tell me how to pass multiples values selected by user in the interface to crystal reports?

Former Member
Former Member replied

Hello,

One way is to use the code found in KB [1273690 - Pass multiple parameter values to one parameter in a Crystal Report|https://bosap-support.wdf.sap.corp/sap/support/notes/1273690].

If you can't visit that link here's the code from the article:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class Form1
Inherits System.Windows.Forms.Form

''CR Variables   
Dim crReportDocument As ReportDocument
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue 
Dim reportPath As String = Application.StartupPath & "\" & "CustomersByCountry.rpt"

Friend WithEvents CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer

#Region " Windows Form Designer generated code "
       Public Sub New()
       MyBase.New()
           'This call is required by the Windows Form Designer.
       InitializeComponent()

'Add any initialization after the InitializeComponent() call
'Create an instance of the report object
crReportDocument = New ReportDocument()
crReportDocument.Load(reportPath)

'Get the collection of parameters from the report
crParameterFieldDefinitions = crReportDocument.DataDefinition.ParameterFields

'Access the specified parameter from the collection
crParameterFieldDefinition = crParameterFieldDefinitions("Country")

'Get the current values from the parameter field.  At this point
'there are zero values set.
crParameterValues = crParameterFieldDefinition.CurrentValues

'Set the current values for the parameter field
crParameterDiscreteValue = New ParameterDiscreteValue()
crParameterDiscreteValue.Value = "Canada" '1st current value

'Add the first current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue)

'Since this parameter allows multiple values, the discrete value
'object needs to be reset.  Destroy the previous instance and create
'a new instance.
crParameterDiscreteValue = Nothing
crParameterDiscreteValue = New ParameterDiscreteValue()
crParameterDiscreteValue.Value = "USA" '2nd current value

'Add the second current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue)

'All current parameter values must be applied for the parameter field.
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

'Set the viewer to the report object to be previewed.
CrystalReportViewer1.ReportSource = crReportDocument

End Sub

Sincerely,

Dan Kelleher

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question