Solved

Pass a parameter from a Windows form to a crystal report in VB.NET

Posted on 2016-09-14
8
141 Views
Last Modified: 2016-09-29
Caution - I need very specific instructions as I am not at all proficient in VB.net or CR.  
I want to enter a strNumber in a textbox on a windows form, and have it passed to a Crystal Report parameter for sorting (CR report is on the same form).

I'm using Visual Studio 2015/VB.net

I created a Windows form named frmSubSpecsReport
I created a Textbox on the form named txtJobNumber and a variable strJobNumber to hold the value that is typed into the textbox
I created a parameter in the report named JobNumber, which I will use to sort through all the jobs to find the correct one
I want to capture the number that a user types into the textbox and pass it to the JobNumber parameter in CR

I've used the Imports at the top of the form:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

I've added this code for the button click event -

        Dim ParameterFields As CrystalDecisions.Shared.ParameterFields
        Dim ParameterField As CrystalDecisions.Shared.ParameterField
        Dim ParameterDiscreteValue As CrystalDecisions.Shared.ParameterDiscreteValue
        Dim strJobNumber As String = txtJobNumber.Text

'assign a report object to the viewer
        Dim crSubSpecsReport As New CrystalReport1    
  I got an error using CrystalReport1 as not being referenced ?? So I added the following to get the error to go away, but really don't know what it does:
Private Class CrystalReport1
    End Class

Then the code continues as follows:
        CrystalReportViewer1.ReportSource = New crSubSpecsReport

        'reference the parameterfields collection
        ParameterFields = CrystalReportViewer1.ParameterFieldInfo

        'reference the ParameterField object (name of the parameter i CR)
        ParameterField = ParameterFields("JobNumber")

        'create a parameterValue object
        ParameterDiscreteValue = New ParameterDiscreteValue

        'assign a default value
        ParameterDiscreteValue.Value = "strJobNumber"

        'add the ParameterValue object to the CurrentValues or DefaultValues collection
        ParameterField.CurrentValues.Add(ParameterDiscreteValue)

When I run the program, the CR parameter input form appears (not what I want) and when I enter a number, it does appear on the report, but if I use the textbox and click the button, then "strJobNumber" appears instead of the number entered.

Thanks very much for taking a look at this!
0
Comment
Question by:Gary Demos
[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
  • 5
  • 3
8 Comments
 

Author Comment

by:Gary Demos
ID: 41798432
I have found another template which works using the ReportDocument class, but it still displays the CR parameter input form first, then after entering a string it moves to the report form where I can enter a string in the textbox, and then click the button and it does display on the report.

My problem now is this - I would like to go directly to the form and bypass the CR parameter dialog.
Here is the code that I changed to:

Private Sub btnViewReport_Click(sender As Object, e As EventArgs) Handles btnViewReport.Click

        Dim crSubSpecsReport As New ReportDocument
        crSubSpecsReport.Load("D:\Visual Studio 2015 Projects\Production Reports\Production Reports\crSubSpecsReport.rpt")
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue
        crParameterDiscreteValue.Value = txtJobNumber.Text
        crParameterFieldDefinitions = crSubSpecsReport.DataDefinition.ParameterFields
        crParameterFieldDefinition =
            crParameterFieldDefinitions.Item("JobNumber")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
        CrystalReportViewer1.ReportSource = crSubSpecsReport
        CrystalReportViewer1.Refresh()


    End Sub
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 41798899
0
 

Author Comment

by:Gary Demos
ID: 41804601
Thanks for the link - I will try it out today!
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:Gary Demos
ID: 41805187
The link above was to a program written in VS 2005 and it would not update to VS2015. I found the code difficult to follow as well since it was using a Dataset and I am using OLE DB connection since I'm connecting to a SQL 2000 DB. I don't know enough to fill in the blanks in coding, and if someone could show me how I need to modify my code above that would be very helpful.

Thanks, Gary
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 41805592
I will look into it but I am not a .Net programmer so I will have similar problems.

mlmcc
0
 

Author Comment

by:Gary Demos
ID: 41812805
Yes the .NET is the part I need help with.
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 500 total points
ID: 41813078
This article from SAP on parameters may help

http://scn.sap.com/docs/DOC-70646

http://scn.sap.com/thread/3942873

mlmcc
0
 

Author Comment

by:Gary Demos
ID: 41816827
Thank you - the first link looks very interesing and informative. I'll dig into it and see how it goes.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

623 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