|
-
Aug 18th, 2010, 02:23 PM
#1
Thread Starter
PowerPoster
[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,
-
Aug 21st, 2010, 01:39 PM
#2
Thread Starter
PowerPoster
Re: Passing a parameter to a Crystal Report?
Any ideas on this???
Thanks,
-
Aug 21st, 2010, 04:40 PM
#3
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.
-
Aug 21st, 2010, 10:03 PM
#4
Thread Starter
PowerPoster
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.
-
Aug 23rd, 2010, 12:21 AM
#5
Re: Passing a parameter to a Crystal Report?
-
Aug 23rd, 2010, 01:23 PM
#6
Thread Starter
PowerPoster
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
-
Aug 30th, 2010, 01:03 AM
#7
Frenzied Member
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
-
Aug 30th, 2010, 11:40 AM
#8
Thread Starter
PowerPoster
Re: Passing a parameter to a Crystal Report?
Yes and actually I already figured this out how I want to do it.
Thanks,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|