Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Subsequent SubReports overwriting earlier parameters

For some reason any subreports that I add overwrite the parameters of the earlier subreports that are added.

I have tried renaming the report name, this happens with totally different subreports... the last one is the only

one that the parameters stick. I get prompted to enter all previous parameters from all but the last subreport.

Here is a simple code snippet that just adds a subreport twice and I get prompted for the first

subreport parameters: (I normally am not running the same report more than once with the same values,

this is only for example purposes)

            Try
                Dim intNewSection As Integer = 0
                Dim boReportDocument As ReportDocument
                Dim boReportClientDocument As ISCDReportClientDocument
                Dim boSubreportClientDocument As CrystalDecisions.ReportAppServer.Controllers.SubreportClientDocument
                Dim boArea As CrystalDecisions.ReportAppServer.ReportDefModel.Area
                Dim boSection As CrystalDecisions.ReportAppServer.ReportDefModel.Section
                Dim sarSubRptFile(1) As String
                Dim strSubRptFile As String
                sarSubRptFile(0) = Application.StartupPath & "\Reports\Selected Checklist.rpt"
                sarSubRptFile(1) = Application.StartupPath & "\Reports\Selected Checklist.rpt"

                boReportDocument = New ReportDocument()

                boReportDocument.Load(strReportFilespec)
                boReportClientDocument = New ReportClientDocumentClass()

                boReportDocument.SetDataSource(dsProject) 'Point the crystal report at the System.Data.DataSet
                boReportClientDocument = boReportDocument.ReportClientDocument

                For Each strSubRptFile In sarSubRptFile
                    'Get the detail area from the report
                    boArea = boReportClientDocument.ReportDefController.ReportDefinition.DetailArea

                    'Create the new section object
                    boSection = New CrystalDecisions.ReportAppServer.ReportDefModel.Section

                    'Set the properties for the section
                    boSection.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindDetail
                    boSection.Name = "CustomDetailSection" & CStr(intNewSection) 'Give it a unique name
                    intNewSection += 1

                    Dim boTestReportDocument As ReportDocument
                    boTestReportDocument = New ReportDocument()
                    boTestReportDocument.Load(strSubRptFile)
                    Dim intSubRptWidth As Integer = boTestReportDocument.ReportClientDocument.ReportDefController.ReportDefinition.PageHeaderArea.Sections(0).Width
                    boTestReportDocument.Close()
                    boTestReportDocument = Nothing
                    boSection.Width = intSubRptWidth

                    'Add the section to the clientdocument
                    boReportClientDocument.ReportDefController.ReportSectionController.Add(boSection, boArea, -1)

                    'Import the sub report with a unique name
                    boSubreportClientDocument = boReportClientDocument.SubreportController.ImportSubreport( _
                     Chr(intNewSection) & Path.GetFileNameWithoutExtension(strSubRptFile), strSubRptFile, boSection)

                    Try
                        Dim rasDataset As ISCRDataSet
                        rasDataset = DataSetConverter.Convert(dsProject)

                        boSubreportClientDocument.DatabaseController.SetDataSource(rasDataset)
                    Catch exData As Exception
                        MsgBox("Error setting data to " & strSubRptFile & vbLf _
                         & "Error: " & exData.ToString, MsgBoxStyle.Information, "Group Report Error")
                    End Try
                    boReportClientDocument.DataDefController.ParameterFieldController.SetCurrentValue( _
                     boSubreportClientDocument.Name, "lowerid", "1a9b-4628-87b1-3026582e0dd6")
                Next

                CrystalReportViewer1.ReportSource = boReportDocument

                CrystalReportViewer1.Show()
            Catch exTest As Exception
            End Try

Does anyone have any idea what I am doing wrong - why is the subreport parameters getting blown away on all but the last subreport.. This happens even if the parameter names are different.

Thanks,

Jeff

Former Member
Not what you were looking for? View more on this topic or Ask a question