tags:

views:

423

answers:

1

Using VB 6 and Crystal Report 8.5

I want to pass the date parameter filed in CRViewer control.

Code:

Dim crApp As CRAXDRT.Application
Dim Report As CRAXDRT.Report
CR2.ParameterFields(1) = "txtFromDate;" & dtpFrom.Value & ";true"
CR2.ParameterFields(2) = "txtToDate;" & dtpTo.Value & ";true"
CR2.DataFiles(0) = App.Path & "\STAR.mdb"
CR2.ReportFileName = App.Path & "\MS.rpt"
Set crApp = New CRAXDRT.Application
Set Report = crApp.OpenReport(App.Path & "\MS.rpt")
CRViewer2.ReportSource = Report
CRViewer2.ViewReport

Parameterfield(1), Parameterfield(2) was not displaying in the crviewercontrol.

How to pass the date parameter field in the CRViewer control?

Need VB 6 code help.

A: 

To my understanding, you have to pass the date to the parameter field in the same format as CR is expecting. Open the report in Crystal Reports, and go to the Edit screen for each parameter field. Make sure the fields are of Date type instead of DateTime as it doesn't seem you need to account for time given your example. Then click on "Set Default Values", this screen will show you the format CR is expecting for the parameter (usually M/D/YYYY). In your code, format your date value to be passed to the parameter:

CR2.ParameterFields(1) = "txtFromDate;" & Format(dtpFrom.Value, "M/D/YYYY") & ";true"
CR2.ParameterFields(2) = "txtToDate;" & Format(dtpTo.Value, "M/D/YYYY") & ";true"

Edit: Or D/M/YYYY, just depends on what CR wants.

Heather