CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2006
    Posts
    1

    Smile Suppress Main report when sub-report return null date

    Hi everyone, I did try to look up the solution on Internet but I haven't found one for that yet. I used Crystal Reports XI to create a report with sub-report. I have two groups in my main report. In order to suppress the main report and sub-report section when sub-report returns null date, I have shared variable and the following logic in main report group headers and detail.

    WhilePrintingRecords;
    Shared DateVar subreportDate;

    If IsNull(subreportDate) Then
    True
    Else
    False

    For some reason, it suppresses the next record instead of the current record. Please help.

    Albert

  2. #2
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Suppress Main report when sub-report return null date

    You may try the next:
    To suppress a section that contains a blank subreport you could create a duplicate subreport.
    Place the duplicate subreport into one section above the section where is the original subreport.
    For example, if the original subreport is contained in the group header of the main report, create another group header and place the duplicate subreport into it.

    To insert a section into the report, complete the following steps:
    1. In design mode, right-click the left gray margin where the subreport is located.
    For example, if the subreport is located in the group header, right-click the left gray margin at the group header level.
    2. From the fly-out menu, select 'Insert Section Below'. You notice another section is inserted into the report labeled 'b'.
    For example, by inserting another group header you notice that there is group header A and group header B.
    3. Select the original subreport, drag and drop it into the second section.
    4. Insert the duplicate subreport by selecting 'Subreport', from the 'Insert' menu.
    5. Select 'Choose a report', from the 'Insert Subreport' dialog box.
    6. Browse to find the duplicate subreport.
    7. Select the report and click 'Open'.
    8. Click 'OK'. The duplicate subreport will be attached to the cursor.
    9. Insert the subreport in the new section (such as group header b from step 2).
    10. In the main report, on the 'Edit' menu click 'Subreport Links'. The top drop-down box will contain both the original and duplicate subreports. Compare these two subreports and enure that the fields in the 'Filed(s) to link to' box are the same. Also, check that the parameter in the bottom-left drop-down box and the field in the bottom-right drop-down box are the same.

    Creating A Formula To Test If The Subreport Is Blank
    In the duplicate subreport, you must create a formula to test whether the contents of the subreport are blank. The results of this formula are going to be stored as a shared variable and shared with the main report.

    To create this formula, complete the following steps:
    1. Right-click on the duplicate subreport and from the fly-out menu, select 'Edit Subreport'.
    2. From the 'Insert' menu, select ' select 'Field Object'. This launches the 'Field Explorer'.
    3. Select 'Formula Fields' and select the 'New' icon.
    4. Type a name into the 'Formula Name' box and click 'OK'. For example, CheckForNull. This launches the formula editor.
    5. Create a formula similar to the following:
    Code:
    // @CheckForNull  
    Whileprintingrecords;  
    Shared BooleanVar Suppress;  
    If  IsNull(Count({Table.field})) or Count(Table.field) = 0 then Suppress:= TRUE  
    Else Suppress:= FALSE
    6. Place @CheckForNull in the Report Header of the duplicate subreport.

    Conditionally Suppressing a Section Containing Original Subreport
    To conditionally suppress the section that contains the original subreport, complete the following steps:

    1. From the 'Format' menu, select 'Section'. This launches the 'Section Expert'.
    2. From the 'Section Expert' dialog box, select the section that contains the original subreport.
    3. Click the 'X+2' button beside the 'Suppress (No drill down) check box. Ensure the checkbox is clear.
    4. In the 'Format Formula Editor', create a formula similar to the following:
    Code:
    // The section will be suppressed if   
    // variable Suppress is True  
    Whileprintingrecords;  
    Shared BooleanVar Suppress = True
    Now when you preview the report, you notice that the sections that contain a blank subreport are suppressed. However, the section that contains the duplicate subreport is visible on the main report. In order to suppress the section still visible you must minimize and resize the section.

    Minimizing the Duplicate Subreport & Resizing the Section
    To minimizing the duplicate subreport on the main report and resize the section, complete the following steps:
    1. From the main report, right-click the duplicate subreport.
    2. From the fly-out menu, select 'Edit subreport'.
    3. Suppress all of the sections in the duplicate report.
    4. Select the main report.
    5. Right-click the duplicate subreport, and from the fly-out menu, select 'Format Subreport'.
    6. From the 'Format Editor', select the 'Border' tab.
    7. From 'Line style', select 'None' for Left, Right, Top, Bottom.
    8. Select the main report.
    9. Resize the section that contains the duplicate subreport to be as small as possible.
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Suppress Main report when sub-report return null date

    Another solution, could be :

    1. In the main report, right-click the subreport object and click 'Edit Subreport'. This
    takes you to the 'Subreport' tab of the main report.
    2. On the 'File' menu, click 'Report Options'.
    3. Select the 'Suppress Printing if No Records' checkbox, and then click 'OK'.
    4. Return to the 'Preview' tab of the main report.
    5. Refresh the report.
    Blank subreports now appear as empty boxes on the report.

    Shrinking a Blank Section
    1. Format the subreport object so there are no borders:
    · on the main report, right-click the subreport object and click 'Format Subreport'.
    · on the 'Borders' tab, select 'None' from the Top, Bottom, Right and Left boxes.
    · Click 'OK' to return to the report.
    2. In 'Design' tab of the main report, resize the height of the subreport object so it is as
    short as possible.
    3. Move the subreport object so it is at the very top of the section.
    4. On the 'Format' menu of the main report, click 'Section'.
    5. Select the section containing the subreport, select the 'Fit Section' checkbox, and then
    click 'OK' to return to the report
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured