I have written a v8.5 Crystal Report for use with the Informix 3.82 database that I am using, and have placed the single parameter that the report requires as a text item in the header of the report.
I can run the CR from Windows Explorer, and after entering the parameter's value on the "Enter Parameter Values" page, the CR will come up with all of the correct data. Yea.
I need to programmatically run this report and pass the parameter in through a
VB.NET program. So I wrote a
VB.NET program that passes the value to the CR and loads it into a Crystal Report Viewer.
The report is displayed in the CR Viewer window, and the parameter that I have passed is displayed in the header of the report, so I know that my parameter has been passed successfully, but aside from the field descriptions, the report is blank, i.e. the titles are there but there is no data displayed.
It is almost like there is something missing from my environment when the report is run via
VB. Could it be something to do with Informix? Does anyone have an idea of what might be causing this issue?
Must I somehow bind the database to the report or the report to the program?
Thanks
CODE:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyReport As New CRTest
CrystalReportViewer1.ReportSource = MyReport
' The parameter is passed to the report, as is witnessed by its
' value being placed on the header of the report, but no data is
' printed on the report
' Either of the following two lines can be used with the same results:
' (1)
' SetParameterDiscreteWithViewer(CrystalReportViewer 1, "Rack", "402074", "")
'
' (2)
SetParameterDiscreteWithReport(MyReport, "Rack", "402074", "")
End Sub
Public Sub SetParameterDiscreteWithReport(ByVal MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocum ent, ByVal ParameterName As String, ByVal Value As Object, ByVal SubreportName As String)
Dim MyParameterFieldDefinition As CrystalDecisions.CrystalReports.Engine.ParameterFi eldDefinition
Dim MyParameterValues As CrystalDecisions.Shared.ParameterValues
Dim MyParameterDiscreteValue As CrystalDecisions.Shared.ParameterDiscreteValue
MyParameterFieldDefinition = MyReport.DataDefinition.ParameterFields.Item("Rack ", "")
MyParameterValues = New CrystalDecisions.Shared.ParameterValues
MyParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
MyParameterDiscreteValue.Value = Value
MyParameterValues.Add(MyParameterDiscreteValue)
MyParameterFieldDefinition.ApplyCurrentValues(MyPa rameterValues)
End Sub
Public Sub SetParameterDiscreteWithViewer(ByVal CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer , ByVal ParameterName As String, ByVal ParameterValue As Object, ByVal SubreportName As String)
Dim MyParameterFields As CrystalDecisions.Shared.ParameterFields
Dim MyParameterField As CrystalDecisions.Shared.ParameterField
Dim MyParameterDiscreteValue As CrystalDecisions.Shared.ParameterDiscreteValue
MyParameterFields = CrystalReportViewer1.ParameterFieldInfo
MyParameterField = MyParameterFields(ParameterName, SubreportName)
MyParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
MyParameterDiscreteValue.Value = ParameterValue
MyParameterField.CurrentValues.Add(MyParameterDisc reteValue)
CrystalReportViewer1.ParameterFieldInfo = MyParameterFields
End Sub