Sub Reports

Sub reports are regular reports contained in a field in another report (the main report).  Sub reports are usually designed to display detailed information based on a current value in the main report, in a master-detail scenario. For example, the main report might contain orders, and a sub report in the detail section will contain order details for the current order.

  1. Make sure you are looking at the report in which you want to add a sub report.

  2. In the left pane, click Add Report.

  3. Follow the steps in the wizard as described in the Create a Designer Report topic. The process is the same.

  4. Place your cursor in the location for the sub report.

  5. Anywhere in the main report, click and drag the sub report to the size you want it.

Link Sub Reports to the Main Report

This master-detail relationship is controlled by the Text property of the sub report field. This property should contain an expression that evaluates into a filter condition that can be applied to the sub report data source.

  1. Right-click the sub report field and select the Link Sub report menu.  

    You are presented with a dialog that allows you to select which fields should be linked.

  2. From the Container Report field, select a report field.

  3. From the Must match sub report field, select a sub report field.

  4. Click OK.  

    The Report Designer builds the link expression and assigns it to the Text property (in the Properties pane) of the sub report field.  

Link Sub Reports to the Main Report with VBScript

  1. Make sure that the data source for both your main and sub report(s) contain a common field.

  2. Place the sub report within the main report in a Group or Section.

  3. Select the header for the section or group that contains the sub report.

  4. In the OnPrint property for the section or group, click the button with the ellipsis (...).  

    The VBScript Editor pop-up window opens.

  5. Where AssetGrpRpt is the Name property on the sub report and IDAssetgroup is the common link between your main report and sub report data, enter the following VBScript:

    '**************************ID AssetGroup *************************
    'Get sub report datasourcesubR=  AssetGrpRpt.sub report.datasource.recordsource
    'find if the subR has a where clausepos2= instr(subR,"where")
    if pos2=0 then'No where clause, then add one using the current IDAssetnewField=subR & " where " & " IDAssetGroup = '" & IDAssetGroup & "'"
    else'delete old where clause, add new one.oldvalue=left(subR,pos2 -1)newField=oldvalue & " where " & " IDAssetGroup =
    '" & IDAssetGroup & "'"
    end if
    'update Subreport Datasource
    AssetGrpRpt.sub report.datasource.recordsource=newfield
    '*****************************************************************
  6. Click OK.

  7. Select the sub report to view its properties.

  8. Remove all values from the Text field.

  9. Repeat for all sub reports within the your main report.