Gary Demos
asked on
Pass a parameter from a Windows form to a crystal report in VB.NET
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.CrystalRe ports.Engi ne
Imports CrystalDecisions.Shared
I've added this code for the button click event -
Dim ParameterFields As CrystalDecisions.Shared.Pa rameterFie lds
Dim ParameterField As CrystalDecisions.Shared.Pa rameterFie ld
Dim ParameterDiscreteValue As CrystalDecisions.Shared.Pa rameterDis creteValue
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.Repor tSource = New crSubSpecsReport
'reference the parameterfields collection
ParameterFields = CrystalReportViewer1.Param eterFieldI nfo
'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.Val ue = "strJobNumber"
'add the ParameterValue object to the CurrentValues or DefaultValues collection
ParameterField.CurrentValu es.Add(Par ameterDisc reteValue)
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!
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.CrystalRe
Imports CrystalDecisions.Shared
I've added this code for the button click event -
Dim ParameterFields As CrystalDecisions.Shared.Pa
Dim ParameterField As CrystalDecisions.Shared.Pa
Dim ParameterDiscreteValue As CrystalDecisions.Shared.Pa
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.Repor
'reference the parameterfields collection
ParameterFields = CrystalReportViewer1.Param
'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.Val
'add the ParameterValue object to the CurrentValues or DefaultValues collection
ParameterField.CurrentValu
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!
Here is a link to working code that does what you want.
http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
mlmcc
http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
mlmcc
ASKER
Thanks for the link - I will try it out today!
ASKER
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
Thanks, Gary
I will look into it but I am not a .Net programmer so I will have similar problems.
mlmcc
mlmcc
ASKER
Yes the .NET is the part I need help with.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you - the first link looks very interesing and informative. I'll dig into it and see how it goes.
ASKER
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
Dim crSubSpecsReport As New ReportDocument
crSubSpecsReport.Load("D:\
Dim crParameterFieldDefinition
Dim crParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
crParameterDiscreteValue.V
crParameterFieldDefinition
crParameterFieldDefinition
crParameterFieldDefinition
crParameterValues = crParameterFieldDefinition
crParameterValues.Clear()
crParameterValues.Add(crPa
crParameterFieldDefinition
CrystalReportViewer1.Repor
CrystalReportViewer1.Refre
End Sub