Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Missing Parameter Values error Post Reply Post New Topic
Author Message
EddiRae
Newbie
Newbie


Joined: 29 Aug 2008
Online Status: Offline
Posts: 30
Quote EddiRae Replybullet Topic: Missing Parameter Values error
    Posted: 09 Dec 2012 at 2:48pm
I am new to using Crystal in VB.net.  I have multiple parameters.  Some of them have multiple values.  I have viewed several sites with suggestions on how to pass these parameters from vb.net to the crystal report viewer and the report.  Below is my code.  I am not sure what is incorrect with it.

Imports System.Data
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data.OleDb

Protected Sub cmdRunReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdRunReport.Click
        Dim dtFromDate As Date
        Dim dtToDate As Date
        Dim strFromDate As String
        Dim strToDate As String
        Dim strDateRange As String
        Dim rptDoc As New ReportDocument

        Dim myPath As String
        Dim crUser As String
        Dim crPwd As String
        Dim crServer As String
        Dim crDatabase As String
        Dim bAll As String
        Dim iCnt As Integer

        txtMsg.Visible = False
        txtMsg.Text = Nothing

        crUser = ConfigurationManager.AppSettings("crUser").ToString
        crPwd = ConfigurationManager.AppSettings("crPwd").ToString
        crServer = ConfigurationManager.AppSettings("crServer").ToString
        crDatabase = ConfigurationManager.AppSettings("crDatabase").ToString

        If ddlReport.SelectedValue = -1 Then
            txtMsg.Text = "You must select a report to preview"
            txtMsg.Visible = True
            ddlReport.Focus()
            Exit Sub
        End If

        dtFromDate = Me.calFromDate.SelectedDate.Date
        If Not IsDate(dtFromDate) Then
            txtMsg.Text = "You must select a from date"
            txtMsg.Visible = True
            calFromDate.Focus()
            Exit Sub
        End If
        dtToDate = Me.calToDate.SelectedDate.Date
        If Not IsDate(dtToDate) Then
            txtMsg.Text = "You must select a to date"
            txtMsg.Visible = True
            calToDate.Focus()
            Exit Sub
        End If

        myPath = Nothing
        Select Case ddlReport.SelectedValue
            Case "106"
                'Load the selected report file
                myPath = Server.MapPath("Nav106.rpt")
        End Select

        Dim paramFields As ParameterFieldDefinitions
        Dim paramField1 As ParameterFieldDefinition
        Dim paramField2 As ParameterFieldDefinition
        Dim paramField3 As ParameterFieldDefinition
        Dim paramField4 As ParameterFieldDefinition
        Dim paramField5 As ParameterFieldDefinition
        Dim paramField6 As ParameterFieldDefinition
        Dim paramField7 As ParameterFieldDefinition
        Dim DiscreteVal As ParameterDiscreteValue
        Dim paramValues As ParameterValues

        'Load Report
        rptDoc.Load(myPath)

        paramFields = rptDoc.DataDefinition.ParameterFields

        strDateRange = "From " & dtFromDate.Date & " to " & dtToDate.Date
        paramField1 = paramFields.Item("DateRange")
        paramValues = paramField1.CurrentValues
        DiscreteVal = New ParameterDiscreteValue
        DiscreteVal.Value = strDateRange
        paramValues.Add(DiscreteVal)
        paramField1.ApplyCurrentValues(paramValues)

        Dim FromDate As String = Format(dtFromDate, "yyyyMMdd")
        strFromDate = FromDate
        paramField2 = paramFields.Item("FromDate")
        paramValues = paramField2.CurrentValues
        DiscreteVal = New ParameterDiscreteValue
        DiscreteVal.Value = strFromDate
        paramValues.Add(DiscreteVal)
        paramField2.ApplyCurrentValues(paramValues)

        Dim ToDate As String = Format(dtToDate, "yyyyMMdd")
        strToDate = ToDate

        paramField3 = paramFields.Item("ToDate")
        paramValues = paramField3.CurrentValues
        DiscreteVal = New ParameterDiscreteValue
        DiscreteVal.Value = strToDate
        paramValues.Add(DiscreteVal)
        paramField3.ApplyCurrentValues(paramValues)

        paramField4 = paramFields.Item("Locs")
        paramValues = paramField4.CurrentValues
        Select Case ddlReport.SelectedValue
            Case 106
                bAll = False
                iCnt = 0
                For Each item As ListItem In lbLocs.Items
                    If item.Value = -1 Then
                        If item.Selected Then
                            bAll = True
                        End If
                    Else
                        If bAll = True Then
                            If iCnt = 0 Then
                                iCnt = 1
                            End If
                            DiscreteVal = New ParameterDiscreteValue
                            DiscreteVal.Value = item.Value
                            paramValues.Add(DiscreteVal)
                        Else
                            If item.Selected Then
                                If iCnt = 0 Then
                                    iCnt = 1
                                End If
                                DiscreteVal = New ParameterDiscreteValue
                                DiscreteVal.Value = item.Value
                                paramValues.Add(DiscreteVal)
                            End If
                        End If
                    End If
                Next
        End Select
        paramField4.ApplyCurrentValues(paramValues)

        paramField5 = paramFields.Item("Agents")
        paramValues = paramField5.CurrentValues
        Select Case ddlReport.SelectedValue
            Case 106
                bAll = False
                iCnt = 0
                For Each item As ListItem In lbAgents.Items
                    If item.Value.ToString = "-1" Then
                        If item.Selected Then
                            bAll = True
                        End If
                    Else
                        If bAll = True Then
                            If iCnt = 0 Then
                                iCnt = 1
                            End If
                            DiscreteVal = New ParameterDiscreteValue
                            DiscreteVal.Value = item.Value
                            paramValues.Add(DiscreteVal)
                        Else
                            If item.Selected Then
                                If iCnt = 0 Then
                                    iCnt = 1
                                End If
                                DiscreteVal = New ParameterDiscreteValue
                                DiscreteVal.Value = item.Value
                                paramValues.Add(DiscreteVal)
                            End If
                        End If
                    End If
                Next
        End Select
        paramField5.ApplyCurrentValues(paramValues)

        paramField6 = paramFields.Item("Status")
        paramValues = paramField6.CurrentValues
        Select Case ddlReport.SelectedValue
            Case 106
                bAll = False
                iCnt = 0
                For Each item As ListItem In lbStatus.Items
                    If item.Value.ToString = "-1" Then
                        If item.Selected Then
                            bAll = True
                        End If
                    Else
                        If bAll = True Then
                            If iCnt = 0 Then
                                iCnt = 1
                            End If
                            DiscreteVal = New ParameterDiscreteValue
                            DiscreteVal.Value = item.Value
                            paramValues.Add(DiscreteVal)
                        Else
                            If item.Selected Then
                                If iCnt = 0 Then
                                    iCnt = 1
                                End If
                                DiscreteVal = New ParameterDiscreteValue
                                DiscreteVal.Value = item.Value
                                paramValues.Add(DiscreteVal)
                            End If
                        End If
                    End If
                Next
        End Select
        paramField6.ApplyCurrentValues(paramValues)

        paramField7 = paramFields.Item("LeadType")
        paramValues = paramField7.CurrentValues
        Select Case ddlReport.SelectedValue
            Case 106
                bAll = False
                iCnt = 0
                For Each item As ListItem In lbLeadType.Items
                    If item.Value.ToString = "-1" Then
                        If item.Selected Then
                            bAll = True
                        End If
                    Else
                        If bAll = True Then
                            If iCnt = 0 Then
                                iCnt = 1
                            End If
                            DiscreteVal = New ParameterDiscreteValue
                            DiscreteVal.Value = item.Value
                            paramValues.Add(DiscreteVal)
                        Else
                            If item.Selected Then
                                If iCnt = 0 Then
                                    iCnt = 1
                                End If
                                DiscreteVal = New ParameterDiscreteValue
                                DiscreteVal.Value = item.Value
                                paramValues.Add(DiscreteVal)
                            End If
                        End If
                    End If
                Next
        End Select
        paramField7.ApplyCurrentValues(paramValues)


        'Set DataBase Login Info
        rptDoc.SetDatabaseLogon(crUser, crPwd, crServer, crDatabase)

        ' Set the Crytal Report Viewer control's source to the report document
        crvReports.ReportSource = rptDoc

        'Provide Parameter Values
        crvReports.EnableParameterPrompt = False
        crvReports.DisplayGroupTree = False

        crvReports.RefreshReport()

        rptValues.Visible = False
        rptViewer.Visible = True
    End Sub


Thanks for your help in advance!!
Eddi Rae
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.