Results 1 to 2 of 2

Thread: passing paramter to CR subreport through VB.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    STL
    Posts
    182

    passing paramter to CR subreport through VB.net

    Hi all, I am having trouble passing parameter values to my Crystal Report 10 report through VB.NET 03. Below is the code I am using. It works fine for everything else (like the main report), EXCEPT when I have a subreport in my report that requires a parameter.

    When going through VB I get a "The parameter is incorrect" error. After the error, in the crystal report viewer if you hit refresh then the Report will ask for the parameters and it will work then. Obviously, it has to do with passing the parameters to the subreport correctly through VB then?

    Does anyone have some suggestions?

    VB Code:
    1. Dim oRpt As New ReportDocument
    2.         oRpt.Load("C:\Program Files\System2\rpts\ABSTL\rptTMreceipt.rpt")
    3.  
    4.         Dim param1Fields As New CrystalDecisions.Shared.ParameterFields
    5.  
    6.         Dim param2Field As New CrystalDecisions.Shared.ParameterField
    7.         Dim param2Range As New CrystalDecisions.Shared.ParameterDiscreteValue
    8.         Dim param3Field As New CrystalDecisions.Shared.ParameterField
    9.         Dim param3Range As New CrystalDecisions.Shared.ParameterDiscreteValue
    10.         Dim param4Field As New CrystalDecisions.Shared.ParameterField
    11.         Dim param4Range As New CrystalDecisions.Shared.ParameterDiscreteValue
    12.         Dim param5Field As New CrystalDecisions.Shared.ParameterField
    13.         Dim param5Range As New CrystalDecisions.Shared.ParameterDiscreteValue
    14.  
    15.         param2Field.ParameterFieldName = "@startdate"
    16.         param3Field.ParameterFieldName = "@tax" 'supreport parameter
    17.         param4Field.ParameterFieldName = "@markup" 'supreport parameter
    18.         param5Field.ParameterFieldName = "@EqMarkup" 'supreport parameter
    19.  
    20.         param2Range.Value = startdate
    21.         param3Range.Value = F9.txtTMsalestax.Text
    22.         param4Range.Value = F9.txtTMmatmarkup.Text
    23.         param5Range.Value = F9.txtTMeqmarkup.Text
    24.  
    25.         param2Field.CurrentValues.Add(param2Range)
    26.         param3Field.CurrentValues.Add(param3Range)
    27.         param4Field.CurrentValues.Add(param4Range)
    28.         param5Field.CurrentValues.Add(param5Range)
    29.  
    30.         param1Fields.Add(param2Field)
    31.         param1Fields.Add(param3Field)
    32.         param1Fields.Add(param4Field)
    33.         param1Fields.Add(param5Field)

  2. #2
    Hyperactive Member johnweidauer's Avatar
    Join Date
    Sep 2002
    Location
    SLC, UT
    Posts
    314

    Question Re: passing paramter to CR subreport through VB.net

    I am not sure if you are still stuck on this one, but here is my code that works:

    Code:
                Dim pf As ParameterField = CrystalReportViewer1.ParameterFieldInfo(0)
                Dim pfv As ParameterDiscreteValue = New ParameterDiscreteValue
    
                Dim pf2 As ParameterField = CrystalReportViewer1.ParameterFieldInfo(1)
                Dim pf2v As ParameterDiscreteValue = New ParameterDiscreteValue
    
                Dim pf3 As ParameterField = CrystalReportViewer1.ParameterFieldInfo(2)
                Dim pf3v As ParameterDiscreteValue = New ParameterDiscreteValue
    
                pfv.Value = Form1.txtUserCode.Text
    
                Select Case Form1.ToolStripComboBox1.Text
                    Case "Primary"
                        pf2v.Value = 1
                        pf3v.Value = 2
                    Case "Secondary"
                        pf2v.Value = 2
                        pf3v.Value = 3
                    Case "Tertiary"
                        pf2v.Value = 3
                        pf3v.Value = 0
                    Case Else
                        pf2v.Value = 1
                        pf3v.Value = 2
                End Select
    
                pf.CurrentValues.Add(pfv)
                pf2.CurrentValues.Add(pf2v)
                pf3.CurrentValues.Add(pf3v)
    I use the embedded viewer, but it looks like you need to specify an index for each parameter field in your declaration.
    To the world you may just be one person, but to this one person, you just might be the world.

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