Results 1 to 4 of 4

Thread: Parameters in Crystal Reports

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2004
    Location
    New York City
    Posts
    69

    Parameters in Crystal Reports

    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
    None for now

  2. #2
    Lively Member
    Join Date
    Nov 2002
    Location
    Malaysia
    Posts
    124

    Re: Parameters in Crystal Reports

    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.

    VB Code:
    1. Try
    2.             Dim aActualVsTarget As ActualVsTarget
    3.             aActualVsTarget = New ActualVsTarget()
    4.             aActualVsTarget.SetDataSource(DsActualVsTarget1)
    5.  
    6.             Dim pval As New ParameterValues()
    7.             Dim disVal As New ParameterDiscreteValue()
    8.             disVal.Value = calendarStart.Value.Date     'Set the discrete Value
    9.             pval.Add(disVal) 'add the parameterdiscretevalue to the collection of parametervalues
    10.             aActualVsTarget.DataDefinition.ParameterFields("startDate").ApplyCurrentValues(pval) 'add the parameter to your report document
    11.  
    12.             disVal.Value = calendarEnd.Value.Date     'Set the discrete Value
    13.             pval.Add(disVal) 'add the parameterdiscretevalue to the collection of parametervalues
    14.             aActualVsTarget.DataDefinition.ParameterFields("endDate").ApplyCurrentValues(pval) 'add the parameter to your report document
    15.             '--------------------------------------------------------------------------------
    16.  
    17.             CRviewerActualVsTarget.DisplayGroupTree = False
    18.             CRviewerActualVsTarget.DisplayToolbar = True
    19.             CRviewerActualVsTarget.Zoom(50)
    20.             CRviewerActualVsTarget.ReportSource = aActualVsTarget
    21.  
    22.         Catch ex As Exception
    23.             MsgBox(ex.Message)
    24.         End Try
    25.     End Sub
    26.  
    27.     'Passing the Start and End Date as Parameters from form's object to the Crystal Report
    28.     Public Sub SetParameter(ByVal paramDef As ParameterFieldDefinitions, ByVal paramName As String, ByVal paramValue As String)
    29.         Dim crParameterFieldDefinition As ParameterFieldDefinition = paramDef.Item(paramName)
    30.         Dim crParameterValues As ParameterValues = crParameterFieldDefinition.CurrentValues
    31.         Dim crParameterDiscreteValue As New ParameterDiscreteValue()
    32.  
    33.         crParameterDiscreteValue.Value = paramValue
    34.         crParameterValues.Add(crParameterDiscreteValue)
    35.         crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    36.     End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2004
    Location
    New York City
    Posts
    69

    Re: Parameters in Crystal Reports

    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
    None for now

  4. #4
    Lively Member
    Join Date
    Nov 2002
    Location
    Malaysia
    Posts
    124

    Re: Parameters in Crystal Reports

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width