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.
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}
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
Re: how to use parameter in crystal report
Quote:
Originally Posted by
sigiK
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.
Re: how to use parameter in crystal report
did you add a parameter "Header" to your report ?