Skip to Content
avatar image
Former Member

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Sep 03, 2008 at 07:43 PM

    I am getting different behaviour, I have pasted some simplified code below that works for me. It imports the same subreport into the main report twice, and sets the first subreport's paramter to 1234 and the second's to abcd.

    Trevor

    SubreportClientDocument scd =rptclientdoc.SubreportController.ImportSubreport ("report0","c:\\param.rpt",rptclientdoc.ReportDefController.ReportDefinition.DetailArea.Sections [0]);
       
      rptclientdoc.DataDefController.ParameterFieldController.SetCurrentValue ("report0","test","1234");
    
      scd =rptclientdoc.SubreportController.ImportSubreport ("report1","c:\\param.rpt",rptclientdoc.ReportDefController.ReportDefinition.DetailArea.Sections [0]);
       
      rptclientdoc.DataDefController.ParameterFieldController.SetCurrentValue ("report1","test","abcd");
    
    

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 12, 2008 at 12:31 PM

    After opening a case with Crystal, it turns out that the order in which I set the datasource was the problem. It must be done in the following order:

    1. Build the report and add all the dynamic subreports.

    2. After all the subreports are in place, then set the data source on each and set it on individual tables instead of applying the entire dataset.

    3. Then finally set the parameters.

    Apparently there is a known issue that setting datasources on subreports can blow away previously set parameters. If this is published anywhere, I was not able to find this. So maybe this can help someone else from going through this pain.

    Thanks for everyone's help!

    Jeff

    Add comment
    10|10000 characters needed characters exceeded