Pass Parameters to subreport vb ocx

Posted on 2006-04-13
Last Modified: 2008-02-01
I have a report with a sub report in it. I have a parameter field in each that handles a date range in that sub report. How do I pass said date range from VB to that sub report? I would guess

    q = Format(dtFrom.Value, "yyyy-mm-dd") & " 00:00:00.000"
    r = Format(dtFrom.Value, "yyyy-mm-dd") & " 00:00:00.000"
    strParm = "date(mgmtprod.rpt); " & q & "," & r & "; TRUE"
    CR.ParameterFields(1) = strParm 'set the parm
    CR.Action = 1

Where dtFrom and dtTo are drop down boxes with dates in them. and date is the paramter name and mgmtprod.rpt is the sub report. When I run this I get invaild parameter name.
Question by:t1clausen
    LVL 7

    Expert Comment

           Dim param1Fileds As New CrystalDecisions.Shared.ParameterFields
            Dim param1Field As New CrystalDecisions.Shared.ParameterField
            Dim param1Range As New CrystalDecisions.Shared.ParameterDiscreteValue

            param1Field.ParameterFieldName = "paraName"                   ' Parameter Name In Crystal Report
            param1Range.Value = Request.QueryString("parameter1")         ' value For Parameter Field
            param1Fileds.Add(param1Field)                                 ' To add parameter in parameterslist
            CrystalReportViewer1.ParameterFieldInfo = param1Fileds        'to pass parameters to report viewer
            CrystalReportViewer1.ReportSource = Request.QueryString("Path") ' Assign Report Source to the viewer
            CrystalReportViewer1.Visible = True
    LVL 2

    Author Comment

    This uses the viewer. I need to use the OCX control. Does this even go for the sub reports?

    I tried getting around it by creating a parameter feild in the main report and linking it to the parameter feild in the subreport but that doesn't work either.
    LVL 42

    Accepted Solution

    I believe you have to pass the parameter to the main report.  For example if you have 2 parameters in the main report and 1 in the subreport then to pass the subreport parameter you would pass:

    CR.ParameterFields(3) = strParm  (1 & 2 go to the main report).

    LVL 2

    Author Comment

    I think I need to go back to the drawing board and see if I can create a SQL veiw that will get me around createing sub reports. Thanks for the help

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
    Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now