How To hide a subreport?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DanielM
    New Member
    • Feb 2007
    • 16

    How To hide a subreport?

    How To hide a subreport?
    I found how to know if the subreport has no data
    (Me.subreportna me.Report.HasDa ta)
    what I didn't find is how to make the sub report unvisibile if it has no data.
    I tried:
    If Not Me.subreportnam e.Report.HasDat a then
    Me.subreportnam e.Report.Visibl e = False
    End If
    but it gave me an error
  • lee123
    Contributor
    • Feb 2007
    • 556

    #2
    hi there you could use this

    Code:
    if subreportname then
       subreportname.visible = true
    else
      subreportname.visible = false
    end if
    lee123

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      The first time you refer to the subreport you are referring to the report itself so you need the .Report

      However, the second time you are referring to the subreport object so you don't use .Report

      You also have to allow for the true event.

      [CODE=vb]
      If Me.subreportnam e.Report.HasDat a then
      Me.subreportnam e.Visible = True
      Else
      Me.subreportnam e.Visible = False
      End If
      [/CODE]

      Comment

      • DanielM
        New Member
        • Feb 2007
        • 16

        #4
        Thanks for your attention, the code was OK,
        but still I have a problem, since my target was to save the space that the balnk subreport takes' and although the sub report was unvisible' still the page was with large blank space, in the palce that the subreports was supposed to sit.
        Do you have any idea how to save the blank space?
        Thanks.
        Last edited by DanielM; Sep 10 '07, 07:31 AM. Reason: spelling

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #5
          Originally posted by DanielM
          Thanks for your attention, the code was OK,
          but still I have a problem, since my target was to save the space that the balnk subreport takes' and although the sub report was unvisible' still the page was with large blank space, in the palce that the subreports was supposed to sit.
          Do you have any idea how to save the blank space?
          Thanks.
          Hi, Daniel.

          Try the following.
          • Set subreport control .CanGrow = Yes
          • Reduce subreport control height to possible minimum
          • Handle subreport.Repor t "On No Data" event
            Code:
            Private Sub Report_NoData(Cancel As Integer)
                Cancel = True
            End Sub

          Comment

          • DanielM
            New Member
            • Feb 2007
            • 16

            #6
            Thanks a lot, but didn't work.
            As much as I understood from searching google, the
            "ON NO DATA" event, does not fire in the subreport.

            Comment

            • FishVal
              Recognized Expert Specialist
              • Jun 2007
              • 2656

              #7
              Originally posted by DanielM
              Thanks a lot, but didn't work.
              As much as I understood from searching google, the
              "ON NO DATA" event, does not fire in the subreport.
              LOL. It is really so.

              But it works without handling event.
              At least in my test:
              Several bound textboxes
              Unbound label
              Unbound checkbox

              Did you shrink an empty report area having reduced subreport control height?

              Comment

              • DanielM
                New Member
                • Feb 2007
                • 16

                #8
                Hi,
                what did you mean "But it works without handling event." ?

                Comment

                • FishVal
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2656

                  #9
                  Originally posted by DanielM
                  Hi,
                  what did you mean "But it works without handling event." ?
                  Screenshot in attachment.
                  Attached Files

                  Comment

                  • barry07
                    New Member
                    • Jan 2007
                    • 47

                    #10
                    Daniel is correct that you don't need an event to hide the subreport. Just make the height of the subreport zero in design view and set CanGrow=Yes and CanShrink=Yes in the properties of the sub report.

                    However, you must also set CanGrow=Yes and CanShrink=Yes for the Report section which contains the subreport (|Detail, Report Footer or whatever)

                    Comment

                    • DanielM
                      New Member
                      • Feb 2007
                      • 16

                      #11
                      Thanks you all for your attention and time, It worked.

                      Comment

                      • FishVal
                        Recognized Expert Specialist
                        • Jun 2007
                        • 2656

                        #12
                        You are welcome.

                        Kind regards,

                        Fish

                        Comment

                        Working...