Results 1 to 5 of 5

Thread: how to use parameter in crystal report

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    how to use parameter in crystal report

    I Wish to pass parameter to Crystal Report. I have Access data base one table named student. I with to select range of data's from that table field named "rno"

    i am using visual basic 6

    I used following code to view crystal report
    ================================================
    Set rs = New ADODB.Recordset
    modConnection.opendb
    rs.Open "select * from STUDENT_M order by rno", cn, adOpenStatic, adLockPessimistic
    Report.Database.SetDataSource rs
    Screen.MousePointer = vbHourglass
    CRViewer1.ReportSource = Report
    CRViewer1.ViewReport

    Screen.MousePointer = vbDefault


    ==========================================
    I am new to crystal report. please guide me how to use parameter in crystal report.


    a.Senthil kumar.

  2. #2
    Member
    Join Date
    May 2007
    Location
    Phalaborwa, South Afirca
    Posts
    48

    Re: how to use parameter in crystal report

    I don't use VB6 but I do something like this.

    you can add as many parameters as are needed for the report.

    Code:
            If dtFromDate <> Nothing And dtToDate <> Nothing Then
                strSelectField = "@dtFromDate=" & dtFromDate.ToString
                strSelectField &= "&@dtToDate=" & dtToDate.ToString
            End If

    in your standard selection of the report


    Code:
                If intCounter1 > 0 And Trim(param) <> "" Then
                    strParValPair = param.Split("&")
                    For index = 0 To UBound(strParValPair)
                        If InStr(strParValPair(index), "=") > 0 Then
                            strVal = strParValPair(index).Split("=")
                            paraValue.Value = strVal(1)
                            currValue = _
                             objReport.DataDefinition.ParameterFields(strVal(0)).CurrentValues
                            currValue.Add(paraValue)
                            objReport.DataDefinition.ParameterFields(strVal(0)).ApplyCurrentValues(currValue)
                        End If
                    Next
                End If

    Then I add Parameters @dtFromDate and @dtToDate in your report.

    you can use them in the select expert

    Code:
    {MediaDetails.PurchaseDate} in {?@dtFromDate} to  {?@dtToDate}
    Thanks
    ___________________________________

    Using VB 2005

  3. #3
    Lively Member
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    109

    Re: how to use parameter in crystal report

    First, add a paramater to your report ...


    Code:
    Dim crRep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    Dim crParHeader As New CrystalDecisions.Shared.ParameterDiscreteValue
    
    crRep.Load(Application.StartupPath & "/Report/" & xReport & ".rpt")
    
    crParHeader.Value = xReportname
    crRep.ParameterFields("Header").CurrentValues.Add(crParHeader)
    
    ' Display or Print
    If xOption = "Display" Then
    CrystalReportViewer.ReportSource = crRep
    Else
    crRep.PrintToPrinter(1, True, 0, 0)
    End If

  4. #4
    New Member
    Join Date
    Dec 2009
    Posts
    6

    Re: how to use parameter in crystal report

    Quote Originally Posted by sigiK View Post
    First, add a paramater to your report ...


    Code:
    Dim crRep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    Dim crParHeader As New CrystalDecisions.Shared.ParameterDiscreteValue
    
    crRep.Load(Application.StartupPath & "/Report/" & xReport & ".rpt")
    
    crParHeader.Value = xReportname
    crRep.ParameterFields("Header").CurrentValues.Add(crParHeader)
    
    ' Display or Print
    If xOption = "Display" Then
    CrystalReportViewer.ReportSource = crRep
    Else
    crRep.PrintToPrinter(1, True, 0, 0)
    End If
    At:
    Code:
    crRep.ParameterFields("Header").CurrentValues.Add(crParHeader)
    NullReferenceException exception is thrown.

  5. #5
    Lively Member
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    109

    Re: how to use parameter in crystal report

    did you add a parameter "Header" to your report ?

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