Main and Subreport with Parameters

Posted by: simon.stone on 19 September 2017, 8:57 am EST

  • Posted 19 September 2017, 8:57 am EST

    I have a defined FlexReport whivh consists of a parent and subreport. The subreport is effectively the detail relating to the main report.

    The two reports share the same parameter ('OrderNo'). I have tried various ways of generating the reports (although I render the report then send directly to a printer as shown below), but cannot get it to work (Note, the report functions perfectly in C1FlexReportDesigner).

            Dim factory As New DatabaseProviderFactory()
    Dim myDb As SqlDatabase

    Dim dsOrderList As New DataSet
    Dim dsOrderDetail As New DataSet
    Dim p As New System.Drawing.Printing.PrinterSettings
    Dim pg As New System.Drawing.Printing.PageSettings

    Dim frMainReport As New C1.Win.FlexReport.C1FlexReport
    Dim frDetailReport As New C1.Win.FlexReport.C1FlexReport

    Dim options As C1PrintOptions = New C1PrintOptions()
    options.PrinterSettings = New PrinterSettings()
    options.PageSettings = New System.Drawing.Printing.PageSettings()
    options.PrinterSettings.PrinterName = "Printer1"


    myDb = factory.Create("sys")

    dsOrderList = sysDb.ExecuteDataSet("GetOrdersStoredProc")

    For Each r In dsOrderList.Tables(0).Rows

    frMainReport.Load("D:\API Spooling Docs\DespatchNotev3.flxr", "DespatchNote")
    frDetailReport.Load("D:\API Spooling Docs\DespatchNotev3.flxr", "DespatchNoteDetail")
    frMainReport.Parameters("OrderNo").Value = r("order_no")
    frDetailReport.Parameters("OrderNo").Value = r("order_no")



    Catch ex As System.Exception
    Debug.Print("Spooling Service encountered an error '" &
    ex.Message & "'", EventLogEntryType.Error)
    Debug.Print("Spooling Service service Stack Trace: " &
    ex.StackTrace, EventLogEntryType.Error)
    End Try

    With the above code in place, the printed output renders the main report perfectly, but the subreport shows an error:

    'Subreport [DespatchNoteDetail] can not be rendered.

    Values specified for report parameters are invalid, or values for some of the parameters are missing'

    Each of [DespatchNote] and [DespatchNoteDetail] have only the same single parameter.

    Where am I going wrong?
  • Replied 19 September 2017, 10:50 am EST

    As suggested in this page I have tried changing the below

    frDetailReport.Load("D:\API Spooling Docs\DespatchNotev3.flxr", "DespatchNoteDetail")


    frDetailReport.Load("D:\API Spooling Docs\DespatchNotev3.flxr", "DespatchNoteDetail")
    frMainReport.Fields("Field33").Subreport = frDetailReport

    (where 'Field33' is the field in frMainReport which contains the subreport), But this states that:

    'Subreport' is not a member of the class FieldBase
  • Marked as Answer

    Replied 20 September 2017, 2:31 am EST


    It seems that you are loading the reports multiple times, once for each row. That is not required here. Loading a report instance once i.e. before the For Next loop would be enough.
    Also, instead of using:

    frDetailReport.Load("D:\API Spooling Docs\DespatchNotev3.flxr", "DespatchNoteDetail")
    frMainReport.Fields("Field33").Subreport = frDetailReport

    You may want to use:

    Dim subreport As SubreportField
    frDetailReport.Load("D:\API Spooling Docs\DespatchNotev3.flxr", "DespatchNoteDetail")
    subreport = TryCast(frMainReport.Fields("Field33"), SubreportField)
    subreport .Subreport = frDetailReport

    This is because SubreportField of FlexReport can be set through code by first accessing the field from the Fields collection of the report and then type casting it to SubreportField type.

    Next, ensure that you are linking the main report and the subreport through the SubreportFilter property of the above typecasted SubreportField. You can learn more about it from the below documentation link:

    Linking the two reports this way may help you avoid using another parameter for the subreport. It has been implemented for you in the attached sample.
    Let us know if you face any further issues.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels