Solved

Crystal Reports - Enter parameter values window appears

Posted on 2008-06-10
7
555 Views
Last Modified: 2013-11-26
Hello experts,

I am learning to program in Visual Basic 2005 for Crystal Reports.  I am following the Walkthroughs included with Visual Studio 2005. I doing the chapterfor "Setting parameters for a report."  When the report opens inside the Form in the CrystalReportViewer control everything works just fine.  But when I try to refresh the report I get the [Enter Parameter Values] window, even though the parameters are already being provided.  Any help will be greatly appreciated.  Thank you.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Collections
 
Public Class Form2
    Private Const PARAMETER_FIELD_NAME As String = "City"
 
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ConfigureCrystalReports()
    End Sub
    Private Sub ConfigureCrystalReports()
        Dim myArrayList As ArrayList = New ArrayList()
        myArrayList.Add("Paris")
        myArrayList.Add("Tokyo")
 
        Dim reportPath As String = Application.StartupPath & "\CustomersByCity.rpt"
        myCrystalReportViewer.ReportSource = reportPath
 
        Dim myParameterFields As ParameterFields = myCrystalReportViewer.ParameterFieldInfo
        SetCurrentValuesForParameterField(myParameterFields, myArrayList)
        defaultParameterValuesList.DataSource = GetDefaultValuesFromParameterField(myParameterFields)
 
    End Sub
    Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo)
        Dim myTableLogOnInfos As TableLogOnInfos = myCrystalReportViewer.LogOnInfo
 
        For Each myTableLogOnInfo As TableLogOnInfo In myTableLogOnInfos
            myTableLogOnInfo.ConnectionInfo = myConnectionInfo
        Next
    End Sub
    Private Sub SetCurrentValuesForParameterField(ByVal myParameterFields As ParameterFields, ByVal myArrayList As ArrayList)
        Dim currentParameterValues As ParameterValues = New ParameterValues()
        For Each submittedValue As Object In myArrayList
            Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
 
            myParameterDiscreteValue.Value = submittedValue.ToString()
            currentParameterValues.Add(myParameterDiscreteValue)
        Next
 
        Dim myParameterField As ParameterField = myParameterFields(PARAMETER_FIELD_NAME)
        myParameterField.CurrentValues = currentParameterValues
    End Sub
    Private Function GetDefaultValuesFromParameterField(ByVal myParameterFields As ParameterFields) As ArrayList
        Dim myParameterField As ParameterField = myParameterFields(PARAMETER_FIELD_NAME)
        Dim defaultParameterValues As ParameterValues = myParameterField.DefaultValues
        Dim myArrayList As ArrayList = New ArrayList()
 
        For Each myParameterValue As ParameterValue In defaultParameterValues
            If (Not myParameterValue.IsRange) Then
                Dim myParameterDiscreteValue As ParameterDiscreteValue = CType(myParameterValue, ParameterDiscreteValue)
 
                myArrayList.Add(myParameterDiscreteValue.Value.ToString())
            End If
        Next
        Return myArrayList
    End Function
 
    Private Sub redisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles redisplay.Click
        Dim myArrayList As ArrayList = New ArrayList()
 
        For Each item As String In defaultParameterValuesList.SelectedItems
            myArrayList.Add(item)
        Next
 
        Dim reportPath As String = Application.StartupPath & "\CustomersByCity.rpt"
        myCrystalReportViewer.ReportSource = reportPath
 
        Dim myParameterFields As ParameterFields = myCrystalReportViewer.ParameterFieldInfo
        SetCurrentValuesForParameterField(myParameterFields, myArrayList)
        defaultParameterValuesList.DataSource = GetDefaultValuesFromParameterField(myParameterFields)
    End Sub
End Class

Open in new window

0
Comment
Question by:fcoit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 7

Accepted Solution

by:
Dauhee earned 500 total points
ID: 21758215
You need to do it in the following format:
ReportDocument.SetParameterValue(name, value)

Also SetCurrentValuesForParameterField passes parameters byval - should change this to byref
0
 

Author Comment

by:fcoit
ID: 21761153
Dauhee,
I tried it in the redisplay event, but I do not see the SetParameter option for the ReportDocument statement.  Which library do I need to import?  Where do I enter the ReportDocument.SetParameterValue(name, value) statement? Can you please give me an example.  Thank you for your time.

0
 
LVL 7

Assisted Solution

by:Dauhee
Dauhee earned 500 total points
ID: 21768031
Hi fcoit,

the library is:

crystaldecisions.crystalreports.engine.reportdocument

You would use it the same as the crystal report viewer such as

dim objReport as reportdocument (instead of reportviewer)
0
 
LVL 7

Expert Comment

by:Dauhee
ID: 21840399
Hi fcoit did you not try crystaldecisions.crystalreports.engine.reportdocument ?
0
 

Author Comment

by:fcoit
ID: 21875973
For the record this is a problem with Crystal Report 10 for Visual Basic, which has not been resolved by CR.  Specially with Windows Vista I have not tested it in XP though.  
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question