[RESOLVED] Passing a parameter to a Crystal Report?
I have a crystal report that I need to pass a parameter to from within my VB.Net app. I've setup the report within my app and not outside it, however, it is using an external datasource. How do I pass the value? Here is my code so far:
Code:
Private Sub frmReports_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Me.MdiParent = frmMDIMain
Me.WindowState = FormWindowState.Maximized
Select Case mRptID
Case "woRpt"
Dim woRpt As rptWorkOrder
woRpt.ParameterFields.Add("wrkID")
woRpt.Load("\Reports\rptWorkOrder.rpt")
End Select
Catch ex As Exception
dErr.ModuleInError = "clsWorkOrders"
dErr.ErrorMsg = ex.Message
dErr.SubProcedure = "frmReports_Load()"
dErr.DisplayErrMsg(dErr.ErrorMsg, dErr.ModuleInError, dErr.SubProcedure)
End Try
End Sub
Thanks,
Re: Passing a parameter to a Crystal Report?
Any ideas on this???
Thanks,
Re: Passing a parameter to a Crystal Report?
The code is creating a new parameter! Wouldn't it already exist in the rpt file.
Which Crystal Library/Version are you using? I have never used Crystal in .NET before but wouldn't the code be something like.
woRpt.Load("\Reports\rptWorkOrder.rpt") 'load the report
woRpt.ParameterFields("wrkID").??? = 123 'access the parameter field in the report
??? = Specific method to set the parameters' value.
Re: Passing a parameter to a Crystal Report?
Not sure what version it is. But it comes with VS 2008, It's either ver. 10 or 11.
The namespace I use is "CrystalDecisions.CrystalReports.Engine"...
By the way...I tried what you suggested but couldn't find an appropriate method.
Re: Passing a parameter to a Crystal Report?
Re: Passing a parameter to a Crystal Report?
jggtz,
I tried your suggestion and the code. However, I got an error on the highlighted line of code (see screenshot for error):
Code:
Private Sub frmReports_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Me.MdiParent = frmMDIMain
Me.WindowState = FormWindowState.Maximized
Select Case mRptID
Case "woRpt"
Dim CR As New ReportDocument
Dim strReportPath As String = "C:\VS Applications\DesignsByDonna\DesignsByDonna\Reports\rptWorkOrder.rpt"
CR.Load(strReportPath)
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldLocation As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
crParameterFieldDefinitions = CR.DataDefinition.ParameterFields
crParameterFieldLocation = crParameterFieldDefinitions.Item("wrkID")
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = workOrder.wrkOrderID
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
crViewer.ReportSource = CR
End Select
Catch ex As Exception
Messagebox.Show(ex.Message)
End Try
End Sub
Re: Passing a parameter to a Crystal Report?
I know you might have already gone thru this.. did you check the spelling of wrkID probably its wrkId..just a thought
Re: Passing a parameter to a Crystal Report?
Yes and actually I already figured this out how I want to do it.
Thanks,