Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Pass parameters to sub report Post Reply Post New Topic
Author Message
StuP
Newbie
Newbie


Joined: 09 Sep 2009
Location: United Kingdom
Online Status: Offline
Posts: 3
Quote StuP Replybullet Topic: Pass parameters to sub report
     Posted: 09 Sep 2009 at 5:17am
I have written a report whose data comes from a stored procedure (which requires 3 parameters - @Year, @RetentionPeriod, @LogonId). The report also has a sub-report, which uses a separate stored procedure to get it's data - it requires 3 parameters to run - @Year, @SiteId and @RetentionPeriod. Within the crystal designer environment I have added sub-report links so that the @RetentionPeriod and @Year parameters of the 2 reports are linked, and so that the @SiteId for the subreport is also linked to a data field from the main report.

The above all works fine when I preview the report from within Crystal (this is Crystal 10), however when I try to run the report from within our web app using a Crystal Viewer control, it asks for the sub report parameters (although not the main report parameters). I cannot seem to get around this, any help would be gratefully received.

The code to load the report using the Crystal Viewer control is below:

        Dim oRpt As ReportDocument
        oRpt = New ReportDocument
        oRpt.Load(Server.MapPath("MyReport.rpt"))
        Dim ci As New CrystalDecisions.Shared.ConnectionInfo
        With ci
            .ServerName = server
            .DatabaseName = database
            .UserID = user_id
            .Password = password
        End With
        ' If the ApplyLogon function fails then return a false for this function.
        ' We are applying logon information to the main report at this stage.
        If (Not ApplyLogon(oRpt, ci)) Then
            Return False
        End If

        ' Declare both a report object as well as a subreport object.
        Dim obj As CrystalDecisions.CrystalReports.Engine.ReportObject
        Dim subobj As CrystalDecisions.CrystalReports.Engine.SubreportObject

        'Loop through all the report objects and locate subreports.
        'If a subreport is found then apply logon information to
        'the subreport.
        For Each OBJ In oRpt.ReportDefinition.ReportObjects
            If (OBJ.Kind = CrystalDecisions.[Shared].ReportObjectKind.SubreportObject) Then
                subobj = CType(OBJ, CrystalDecisions.CrystalReports.Engine.SubreportObject)
                If (Not ApplyLogon(oRpt.OpenSubreport(subobj.SubreportName), ci)) Then
                    Return False
                End If
            End If
        Next

        CrystalReportViewer1.ReportSource = oRpt
        CrystalReportViewer1.DisplayGroupTree = False
        CrystalReportViewer1.DataBind()


    Private Function ApplyLogon(ByVal cr As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal ci As CrystalDecisions.Shared.ConnectionInfo) As Boolean

        Dim li As CrystalDecisions.Shared.TableLogOnInfo
        Dim tbl As CrystalDecisions.CrystalReports.Engine.Table

        For Each tbl In cr.Database.Tables
            li = tbl.LogOnInfo
            li.ConnectionInfo = ci
            tbl.ApplyLogOnInfo(li)

            If (tbl.TestConnectivity()) Then
                If (tbl.Location.IndexOf(".") > 0) Then
                    tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)
                Else
                    tbl.Location = tbl.Location
                End If
                tbl.LogOnInfo.ConnectionInfo.ServerName = ci.ServerName
            Else
                Return False
            End If
        Next
        Return True
    End Function

IP IP Logged
StuP
Newbie
Newbie


Joined: 09 Sep 2009
Location: United Kingdom
Online Status: Offline
Posts: 3
Quote StuP Replybullet Posted: 10 Sep 2009 at 9:23am
Ok, this appears to be a Crystal bug. The following knowledge base article and subsequent hotfix has resolved my issue!
c2018840 
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum