PDA

Click to See Complete Forum and Search --> : Parameters in Crystal Reports


usa_dreamer2002
Jan 16th, 2006, 10:28 PM
Hi guys. I have a windows form and would like to print reports from data stored in an MS Access database. I have found many tutorials about Crystal reports However, I dont seem to understand the following:

- Creating a report like a Master/Details form where I have a customer data in the report header and details pertaining only to that customer in the detail section.

- Adding parameters so that I can select transactions between two dates or by transaction type (which are fields in the form in VB .Net).

Can anyone point me to a sample code or tutorial. I have tried reading 101 Microsoft VB.NET Applications but it is not easy to follow to a beginner.
I will Appreciate your help

chinhow
Jan 17th, 2006, 01:55 AM
I have 2 parameters field added in crystal report which are "startDate" and "endDate" and get the these 2 dates from calendar and pass to crystal report. Below is the sample code, hope this is what you want.


Try
Dim aActualVsTarget As ActualVsTarget
aActualVsTarget = New ActualVsTarget()
aActualVsTarget.SetDataSource(DsActualVsTarget1)

Dim pval As New ParameterValues()
Dim disVal As New ParameterDiscreteValue()
disVal.Value = calendarStart.Value.Date 'Set the discrete Value
pval.Add(disVal) 'add the parameterdiscretevalue to the collection of parametervalues
aActualVsTarget.DataDefinition.ParameterFields("startDate").ApplyCurrentValues(pval) 'add the parameter to your report document

disVal.Value = calendarEnd.Value.Date 'Set the discrete Value
pval.Add(disVal) 'add the parameterdiscretevalue to the collection of parametervalues
aActualVsTarget.DataDefinition.ParameterFields("endDate").ApplyCurrentValues(pval) 'add the parameter to your report document
'--------------------------------------------------------------------------------

CRviewerActualVsTarget.DisplayGroupTree = False
CRviewerActualVsTarget.DisplayToolbar = True
CRviewerActualVsTarget.Zoom(50)
CRviewerActualVsTarget.ReportSource = aActualVsTarget

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Passing the Start and End Date as Parameters from form's object to the Crystal Report
Public Sub SetParameter(ByVal paramDef As ParameterFieldDefinitions, ByVal paramName As String, ByVal paramValue As String)
Dim crParameterFieldDefinition As ParameterFieldDefinition = paramDef.Item(paramName)
Dim crParameterValues As ParameterValues = crParameterFieldDefinition.CurrentValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue()

crParameterDiscreteValue.Value = paramValue
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
End Sub

usa_dreamer2002
Jan 17th, 2006, 04:03 PM
Thanks for the reply chinhow, can you also tell me how to insert the parameter fields in the report? I am quiet new at CR .Net.
Thanks again

chinhow
Jan 17th, 2006, 06:06 PM
there is a Field Explorer tab which is left panel of the Visual studio .net. Right click the "Parameter fields" and choose "new". Type in the name and choose the "Discrete Value" radio button and click "ok".
After clicked the OK button, one parameter field is been created and the name will be shown as you typed earlier during parameter field creation. drag that field to the crystal report.

Hope this can help you.

Best Regards,
chinhow