Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameters supplied from a form

Status
Not open for further replies.

davepruce

Programmer
Dec 18, 2001
17
0
0
GB
Hi
Can somebody please explain to me the relationship between parameters created in the code behind a VB.Net button on a form, and the parameters created in a Crystal Report that is 'fired' by the button.(I'm a real CR newbie - no courses, just the net!)
Let me explain.
I had a Crystal Report that took two tables, matched them on a key and reported on the join.
I then added a parameter (ParaGin) to the report and did a match to a database field in the Group Selection Formula Editor then carried on as before.
This was fine, when it ran it popped up a dialog box to get the value then matched on that and produced the report.
Then another related key was required which again worked fine (ParaFault), but we now have 2 separate (huge) dialog boxes asking for input.
So, lets get hold of the parameters in a form before we call the report, pass the parameters and skip the dialog boxes. Much neater and more professional. So how the heck do I do it. The following is the code behind the button and appears to work as far as collecting the data goes, but its ignored when the report is created. The dialog boxes still appear!
(Incidentally, if the guy who wrote this code originally sees this - Thanks)

Private Sub bRunReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bRunReport.Click
Dim CrystalReportViewer1 As New CrystalReportViewer()
Dim frmPumpsReport As New frmShowPumpsRpt()
Dim ParameterFields As ParameterFields
Dim ParameterValues As ParameterValues

'Create an instance of the report
frmPumpsReport = New frmShowPumpsRpt

'Connect to Viewer
CrystalReportViewer1.ReportSource = gblReportSource+"PumpsReportByGIN.rpt"

'Get the Parameters collection from the Viewer
ParameterFields = CrystalReportViewer1.ParameterFieldInfo

'Get parameters
Dim GINNoFld As ParameterField = ParameterFields.Item("ParaGin")
Dim FaultTypeFld As ParameterField = ParameterFields.Item("ParaFault")

'set up ParameterValues to hold the value to pass to the viewer before execution
ParameterValues = GINNoFld.CurrentValues
ParameterValues = FaultTypeFld.CurrentValues

Dim GINNo As ParameterDiscreteValue = New ParameterDiscreteValue
GINNo.Value = txtGinNo.Text
GINNoFld.CurrentValues.Add(GINNo)
ParameterValues.Add(GINNo)

Dim FaultType As ParameterDiscreteValue = New ParameterDiscreteValue
FaultType.Value = txtFaultType.Text
FaultTypeFld.CurrentValues.Add(FaultType)
ParameterValues.Add(FaultType)
CrystalReportViewer1.ParameterFieldInfo = ParameterFields

frmPumpsReport.ShowDialog()

End Sub

Sorry its a bit long but its the only way I could convey my question fully.
Hopefully someone can help.
Cheers
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top