Results 1 to 8 of 8

Thread: [RESOLVED] Passing a parameter to a Crystal Report?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Resolved [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,
    Blake

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Passing a parameter to a Crystal Report?

    Any ideas on this???

    Thanks,
    Blake

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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.
    Blake

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

    Re: Passing a parameter to a Crystal Report?


  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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
    Blake

  7. #7
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    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

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Passing a parameter to a Crystal Report?

    Yes and actually I already figured this out how I want to do it.

    Thanks,
    Blake

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