[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 700
  • Last Modified:

Crystal Reports - passing parameters

I am writing a program that uses a control collection created dynamically depending on the report to be displayed. I have set the .Tag value to ParameterFieldDefinition.Name. The report that I am using to test the program has 'Division', 'Department', 'FromDate' and 'ToDate'. When I run the program as is (with the   'ParameterValues.Add(ParameterDescreteValue) commented out) the last parameter is prompted for ('ToDate'). If I uncomment the line I get a 'Invalid object type' message. Please help.


 Private Sub btnViewReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewReport.Click
        Dim MyReport As ReportDocument
        MyReport = MainForm.MyReport
        Dim control As Control
        Dim dtDate As Date
        Dim parameterFieldDefinitions As ParameterFieldDefinitions = MyReport.DataDefinition.ParameterFields
        Dim ParameterFieldDefinition As ParameterFieldDefinition
        Dim ParameterValues As New ParameterValues
        Dim ParameterDescreteValue As ParameterDiscreteValue
        Dim frmReportViewer As New frmReportViewer

        ProjectForms.ReportViewerForm = frmReportViewer
        MyReport.SetDatabaseLogon("REPORTS", "VbCrystal")

        For Each control In Controls
            If Not (control.Tag = "") Then
                ParameterFieldDefinition = MyReport.DataDefinition.ParameterFields.Item(control.Tag)
                ParameterDescreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
                If TypeOf control Is DateTimePicker Then
                    dtDate = Convert.ToDateTime(control.Text)
                    ParameterDescreteValue.Value = dtDate
                Else
                    ParameterDescreteValue.Value = control.Text
                End If
            End If
            'ParameterValues.Add(ParameterDescreteValue)
        Next

        ParameterFieldDefinition.ApplyCurrentValues(ParameterValues)
        ReportViewerForm.CrystalReportViewer1.ReportSource = MyReport

        ReportViewerForm.Show()
    End Sub
0
Iron01
Asked:
Iron01
1 Solution

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now