Crystal Reports with parameters...again.

T

Tony K

I want to create a report to show information using parameters. I have
setup the report to accept parameters but I want the parameters to come from
a WinForm that shows the same info in a datagridview on a separate WinForm
and not ask the question as the form loads.

Last week, Terry gave me the following code but I'm stupid when it comes to
Crystal Reports.
Private Sub ConfigureCrystalReports()
MyCrystalReportViewer.ReportSource = myReportDocument
Dim myParameterFields As ParameterFields =
MyCrystalReportViewer.ParameterFieldInfo
SetDateRange(myParameterFields,
StartDateTimePicker.Value.ToShortDateString,
StopDateTimePicker.Value.ToShortDateString)
End Sub

Private Sub SetDateRange(ByVal myParameterFields As ParameterFields,
ByVal startDate As String, ByVal
endDate As String)
Dim myParameterRangeValue As ParameterRangeValue = New
ParameterRangeValue()
myParameterRangeValue.StartValue = startDate
myParameterRangeValue.EndValue = endDate
myParameterRangeValue.LowerBoundType = RangeBoundType.BoundInclusive
myParameterRangeValue.UpperBoundType = RangeBoundType.BoundInclusive
Dim myParameterField As ParameterField =
myParameterFields("DateRange")
myParameterField.CurrentValues.Clear()
myParameterField.CurrentValues.Add(myParameterRangeValue)
End Sub


*****MY QUERY IS*****(Access DB)
SELECT [Inventory Transactions].TransactionDate, [Inventory
Transactions].TransactionDescription,
[Inventory Transactions].UnitsSold, Products.ProductIDNumber,
Products.ProductDescription, Suppliers.SupplierName
FROM (([Inventory Transactions] INNER JOIN
Products ON [Inventory Transactions].ProductID = Products.ProductID)
INNER JOIN
Suppliers ON Products.SupplierID = Suppliers.SupplierID)
WHERE ([Inventory Transactions].TransactionDate >= ?) AND
([Inventory Transactions].TransactionDate <= ?) AND
([Inventory Transactions].UnitsSold > 0)
ORDER BY Suppliers.SupplierName

How would I set my parameters from my WinForm that has 2 date fields.
Basically, how would I pass any parameters from an existing form to my CR?
My reportViewer is on a NEW form...right? I'm sorry for the stupidity. I
hope you understand. I just don't know how/where I place the above code
that was given to me last week.

Tony K.
 
T

Terry

Hi Tony,
You have a lot of choices to accomplish what I think you are trying to
do, but first I have to ask a question or 2. If you are reporting on the
same result set that you have in the datagridview, why not use the same
datasource for the report as you do for the the dgv? In other words, why go
back to the database again - just 'push' the data to the report.
It sounds like you have set up a CR viewer form for the report. Either
create a Sub New() for the CRviewer form that takes the two dates when you
instanciate it or add 2 properties for the dates to the form that you can set
after you create the form and before you show it.
So, on the original form when the user selects to print the results...

Dim f as new MyCRviewerForm(StartDate,StopDate)
f.show 'or showdialog
or...
dim f as new MyCRviewerForm
f.startdate = StartDate
f.stopdate = StopDate
f.show 'or showdialog

--
Terry


Tony K said:
I want to create a report to show information using parameters. I have
setup the report to accept parameters but I want the parameters to come from
a WinForm that shows the same info in a datagridview on a separate WinForm
and not ask the question as the form loads.

Last week, Terry gave me the following code but I'm stupid when it comes to
Crystal Reports.
Private Sub ConfigureCrystalReports()
MyCrystalReportViewer.ReportSource = myReportDocument
Dim myParameterFields As ParameterFields =
MyCrystalReportViewer.ParameterFieldInfo
SetDateRange(myParameterFields,
StartDateTimePicker.Value.ToShortDateString,
StopDateTimePicker.Value.ToShortDateString)
End Sub

Private Sub SetDateRange(ByVal myParameterFields As ParameterFields,
ByVal startDate As String, ByVal
endDate As String)
Dim myParameterRangeValue As ParameterRangeValue = New
ParameterRangeValue()
myParameterRangeValue.StartValue = startDate
myParameterRangeValue.EndValue = endDate
myParameterRangeValue.LowerBoundType = RangeBoundType.BoundInclusive
myParameterRangeValue.UpperBoundType = RangeBoundType.BoundInclusive
Dim myParameterField As ParameterField =
myParameterFields("DateRange")
myParameterField.CurrentValues.Clear()
myParameterField.CurrentValues.Add(myParameterRangeValue)
End Sub


*****MY QUERY IS*****(Access DB)
SELECT [Inventory Transactions].TransactionDate, [Inventory
Transactions].TransactionDescription,
[Inventory Transactions].UnitsSold, Products.ProductIDNumber,
Products.ProductDescription, Suppliers.SupplierName
FROM (([Inventory Transactions] INNER JOIN
Products ON [Inventory Transactions].ProductID = Products.ProductID)
INNER JOIN
Suppliers ON Products.SupplierID = Suppliers.SupplierID)
WHERE ([Inventory Transactions].TransactionDate >= ?) AND
([Inventory Transactions].TransactionDate <= ?) AND
([Inventory Transactions].UnitsSold > 0)
ORDER BY Suppliers.SupplierName

How would I set my parameters from my WinForm that has 2 date fields.
Basically, how would I pass any parameters from an existing form to my CR?
My reportViewer is on a NEW form...right? I'm sorry for the stupidity. I
hope you understand. I just don't know how/where I place the above code
that was given to me last week.

Tony K.
 
T

Terry

PS. The code I gave you is 'styled' on using a CR report viewer. But again,
if the user is looking at the data on a dgv and wants to report on it, why
send it to a CR viewer first? Why not just go to the printer directly?
in that case, depending on whether you are using the embeded or non-embeded
approach...

Embedded...
Dim MyRpt as New <MyReport>
Non-Embeded
Dim rp as string ="<the path to the CR report file>"
Dim MyRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
MyRpt.Load(rp)
.....from here it is the same....
Dim myParameterFields As CrystalDecisions.Shared.ParameterFields =
MyRpt.ParameterFields
----Now did you set up 2 discrete parameters or 1 range parameter?
Dim myParam As New CrystalDecisions.Shared.ParameterDiscreteValue
myParam.Value = <StartDate>
Dim myParameterField As CrystalDecisions.Shared.ParameterField =
myParameterFields("StartDate")
myParameterField.CurrentValues.Clear()
myParameterField.CurrentValues.Add(myParam)
.....same for stop date
or if you set up a range parameter....
.....follow the code I already sent you
and then print the report....
myRpt.PrintOptions.PrinterName = <printer name>
myRpt.PrintToPrinter(1, False, 1, 0)

HTH
--
Terry


Tony K said:
I want to create a report to show information using parameters. I have
setup the report to accept parameters but I want the parameters to come from
a WinForm that shows the same info in a datagridview on a separate WinForm
and not ask the question as the form loads.

Last week, Terry gave me the following code but I'm stupid when it comes to
Crystal Reports.
Private Sub ConfigureCrystalReports()
MyCrystalReportViewer.ReportSource = myReportDocument
Dim myParameterFields As ParameterFields =
MyCrystalReportViewer.ParameterFieldInfo
SetDateRange(myParameterFields,
StartDateTimePicker.Value.ToShortDateString,
StopDateTimePicker.Value.ToShortDateString)
End Sub

Private Sub SetDateRange(ByVal myParameterFields As ParameterFields,
ByVal startDate As String, ByVal
endDate As String)
Dim myParameterRangeValue As ParameterRangeValue = New
ParameterRangeValue()
myParameterRangeValue.StartValue = startDate
myParameterRangeValue.EndValue = endDate
myParameterRangeValue.LowerBoundType = RangeBoundType.BoundInclusive
myParameterRangeValue.UpperBoundType = RangeBoundType.BoundInclusive
Dim myParameterField As ParameterField =
myParameterFields("DateRange")
myParameterField.CurrentValues.Clear()
myParameterField.CurrentValues.Add(myParameterRangeValue)
End Sub


*****MY QUERY IS*****(Access DB)
SELECT [Inventory Transactions].TransactionDate, [Inventory
Transactions].TransactionDescription,
[Inventory Transactions].UnitsSold, Products.ProductIDNumber,
Products.ProductDescription, Suppliers.SupplierName
FROM (([Inventory Transactions] INNER JOIN
Products ON [Inventory Transactions].ProductID = Products.ProductID)
INNER JOIN
Suppliers ON Products.SupplierID = Suppliers.SupplierID)
WHERE ([Inventory Transactions].TransactionDate >= ?) AND
([Inventory Transactions].TransactionDate <= ?) AND
([Inventory Transactions].UnitsSold > 0)
ORDER BY Suppliers.SupplierName

How would I set my parameters from my WinForm that has 2 date fields.
Basically, how would I pass any parameters from an existing form to my CR?
My reportViewer is on a NEW form...right? I'm sorry for the stupidity. I
hope you understand. I just don't know how/where I place the above code
that was given to me last week.

Tony K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top