Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB & Crystal Reports with Parameters

Status
Not open for further replies.

collib

Programmer
Oct 18, 2002
14
CA
I have created a report in crystal with two parameters fields called @From_date and @To_Date and they are both strings in Crytsal. How do I pass the parameters into this report. Stuff that has ' in front of it is stuff I was playing with to try and get it to work

Here is my code

Dim CrystalApp As New CRAXDRT.Application
Dim CrystalRpt As New CRAXDRT.Report
'Dim CPFromDate As New CRAXDRT.ParameterValueInfo
'Dim CPToDate As New CRAXDRT.ParameterValueInfo

Set CrystalApp = CreateObject("CrystalRunTime.Application")

Set CrystalRpt = CrystalApp.OpenReport("C:\Visual Basic\Chris\Reports\Chris.rpt")
CrystalRpt.ParameterFields.Add "@From_Date"
CrystalRpt.ParameterFields.Add "@To_Date"
'Set CPFromDate.parameterName = From_Date
'Set CPFromDate.ParameterValues = gFromDate

'Set CPToDate.parameterName = To_Date
'Set CPToDate.ParameterValues = gToDate

'Set CrystalRpt = CrystalApp.OpenReport(Me.ReportDirectory & Me.ReportName)
frmClientReport.crvClient.ReportSource = CrystalRpt
'CrystalRpt.RecordSelectionFormula = Me.WhereClause
frmClientReport.crvClient.ViewReport
 
CrystalRpt.ParameterFields(1).SetCurrentValue From_Date
CrystalRpt.ParameterFields(2).SetCurrentValue To_Date

I am not a big expert on crystal but I think that if the parameters are already created in the .rpt file I don't think you need to create them again in your application. I think you just have to set its current value... that's what works for me anyway
 
Try the following

CrystalRpt.ParameterFields("From_Date").AddCurrentValue gFromDate

 
I do it similar to what robctech mentioned. I also include a line to make sure the parameter value is cleared before the .AddCurrentValue.

Set crxParam = crxReport.ParameterFields.Item(1)
crxParam.ClearCurrentValueAndRange
crxParam.AddCurrentValue <your value>


Thanks and Good Luck!

zemp
 
If I use

CrystalRpt.ParameterFields(&quot;From_Date&quot;).AddCurrentValue CStr(gFromDate)

@from_date is a string I get type mismatch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top