Cannot hide empty subreport

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RicelandIT
    New Member
    • Feb 2012
    • 11

    Cannot hide empty subreport

    I've reviewed the posts on www.bytes.com.
    My problem is the same as that reported by others:
    a report with an empty subreport cannot suppress the display of the empty subreport. I've set the "can shrink" and "can grow" properties to "yes" on both the footer and the subreport's control object. I've also minimized the physical size of the subreport in the footer. These all seem to make no difference. So, I added code to the "format footer" event of the report, attempting to hide the subreport if the .HasData property is false. I've also tried to add code (suggested in other related threads on this web site), which seems to compile without problem, but is unable to make the subreport non-visible. Please see attached JPG for example of empty "Additions (Subtractions)" subreports. I'm desperate! If you help me I will be your friend for life. Seriously.
    [IMGNOTHUMB]http://bytes.com/attachments/attachment/6077d1329110982/hide-subreport-example.jpg[/IMGNOTHUMB]
    Attached Files
    Last edited by NeoPa; Feb 13 '12, 02:37 PM. Reason: Made pic viewable
  • Mihail
    Contributor
    • Apr 2011
    • 759

    #2
    I'm afraid that no one become your friend.

    That because a report is not interactive (since 2007 at least).
    So, when you design a report you reserve spaces for all you need to show in before you run it (at design time).

    I'll be happy for you even if other one will become your friend for a life :) , but I have serious doubt that will happen.

    Good luck !

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32634

      #3
      Unfortunately the picture is too small to see anything helpful, but I sort of get the gist of what you're after. Which version of Access are you using by the way?

      Is there anything else in the Footer Section that should display if the Subreport doesn't?
      Gett ing the Subreport not to show should be easy. I'm guessing your problem is with getting the Footer Section not to show when there's no data in it. This is more involved than you've mentioned. The Subreport control won't shrink related to the lack of data. It has a designed size and that won't be effected by any data or lack thereof.

      I would expect, as long as there is nothing else to print in the Footer Section, that the approach would be to set its visibility to False when there is no Subreport data. Not forgetting to set it to True when there is of course (IE. Set it each time regardless of the data, but to a value that depends on the data).
      Last edited by NeoPa; Feb 13 '12, 03:13 PM. Reason: Added version question

      Comment

      • RicelandIT
        New Member
        • Feb 2012
        • 11

        #4
        I'm using Access 2007. There is nothing else in the footer. There are 2 footers: one for the day of the week and another for the employee. (Report lists data by employee, then for each employee data appears for each day of the week.) The employee footer always has data, but the day of the week footer may not, and the subreport contained in the day of the week footer is the one I'm trying to hide. I've tried to set its visibility to FALSE regardless of whether there is data, and it still appears. Here is the code I placed into the footer's "On Format" event:
        Code:
        Me.TotalEmpItemsDaysubreport2.Visible = False
        Last edited by NeoPa; Feb 13 '12, 11:02 PM. Reason: Added mandatory [CODE] tags for you

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32634

          #5
          Your single line of code doesn't include anything that indicates that this should be dependent on the presence or absence of records in a subreport anywhere. By the time of the Format event I would expect it is too late anyway. At that point setting Cancel = True would be required to ensure the section isn't printed for that particular instance.

          Comment

          • RicelandIT
            New Member
            • Feb 2012
            • 11

            #6
            As I said before, I set its visibility to FALSE because it didn't appear that the if-else-endif block was functioning properly. The entire block of code is the following:
            Code:
                If Me.TotalEmpItemsDaysubreport2.Report.HasData Then
                    Me.TotalEmpItemsDaysubreport2.Visible = True
                Else
                    Me.TotalEmpItemsDaysubreport2.Visible = False
                End If
            If the "on format" event is too late, then what difference does it make whether or not I check the .HasData property? The answer to that question is irrelevant.

            I've seen other similar threads on this web site that suggested putting the code into the "on format" event.

            NeoPa posted the following on a similar thread on this web site:
            "If you know the report will only ever run as a subreport then you can handle the event with code that hides the SubReport control on the main report. "

            What is this code to which you are referring above? In what event should it be placed?
            Last edited by NeoPa; Feb 14 '12, 02:09 PM. Reason: Added mandatory [CODE] tags for you

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32634

              #7
              Originally posted by RicelandIT
              RicelandIT:
              If the "on format" event is too late, then what difference does it make whether or not I check the .HasData property? The answer to that question is irrelevant.
              This sounds confused. Of course it's not irrelevant. The answer determines what is required, and has no bearing on the approach used. The approach used at that point in the code (Setting Cancel = True.) is different from the approach you've used, which may work at an earlier stage, but not there. Whichever approach is used, the logic must still be implemented.

              I was rather hoping to see the whole procedure posted, but at least we know it's in a Format event procedure, so it should now look something like :
              Code:
              Private Sub XXX_Format(Cancel As Integer, FormatCount As Integer)
                  If Not Me.TotalEmpItemsDaysubreport2!HasData Then Cancel = True
              End Sub
              Originally posted by RicelandIT
              RicelandIT:
              What is this code to which you are referring above? In what event should it be placed?
              Hard for me to say with just this to work from. A link may help, but let's see if this works adequately first, shall we.

              Comment

              • RicelandIT
                New Member
                • Feb 2012
                • 11

                #8
                Here's the code:

                Code:
                Private Sub GroupFooter3_Format(Cancel As Integer, FormatCount As Integer) 
                    If !Me.TotalEmpItemsDaysubreport2.Report.HasData Then
                        Cancel = True
                    End If 
                End Sub
                It doesn't matter if we use "!Me" or "Me.": the empty subreports continue to show up.
                Last edited by NeoPa; Feb 15 '12, 04:29 PM. Reason: Added mandatory [CODE] tags for you

                Comment

                • Mihail
                  Contributor
                  • Apr 2011
                  • 759

                  #9
                  Hi again !
                  As I see you really need that.

                  Why not consider to print directly to a file what you wish ?
                  It is a hard work but is doable.

                  Take a look here,

                  and see if that can be a way to accomplish your task.

                  I think I can help you with a sub-routine like that:
                  PrintInFile(New Row As Boolean, Column As Integer, LengthOfColumn As Integer, Alignment As String)

                  I must warn you, again, that will be a hard work for you.
                  And the aspect of the report will not be as nice as Access can do.

                  Comment

                  • wire
                    New Member
                    • Feb 2012
                    • 2

                    #10
                    You might consider making the 'final product' in Crystal Reports. Crystal has a very strong feature in that it can overlay a section of a report -underneath- another section. I've also been able to tweak sub-reports to take a minimal amount of space.

                    I've had fun with sub-reports in both Access and Crystal and If it's important enough make the sub-reports not expand then you'd be better served by Crystal.

                    Comment

                    • RicelandIT
                      New Member
                      • Feb 2012
                      • 11

                      #11
                      I would prefer not to use a complex workaround. Such a solution will likely create more issues I cannot resolve in the future. I saw in another post that it is best to change the SQL so that the empty subreport is not retrieved, but I don't understand where that SQL is physically located so that I could try a different type of join between my report and subreport. (This might not even be making sense.)

                      Maybe there is something obvious I am not communicating. Is there a place I could post my application so a more knowledgable person could run this report and see what happens?

                      Comment

                      • RicelandIT
                        New Member
                        • Feb 2012
                        • 11

                        #12
                        I am not familiar with Crystal Reports. I'm already having to learn Access from scratch, and have invested about 50 hours into this application. (I was formerly a Visual Studio.NET developer, but no longer work at that company, and no longer have access to that development platform.)

                        Is it, or is it not possible to hide an empty subreport?

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32634

                          #13
                          Please read [CODE] Tags Must be Used.

                          Originally posted by RicelandIT
                          RicelandIT:
                          It doesn't matter if we use "!Me" or "Me.": the empty subreports continue to show up.
                          One of those (exactly as stated) will not work at all. Me! will behave in almost all situations (and certainly this one) just as Me.. I fail to see why this isn't working, assuming you used the code I gave rather than what you've posted (which wouldn't be expected to work).

                          If this isn't working for you then I think this is a good time to offer to look at your database. I have a strong suspicion (from what you've said and all the attempts that you've reported as failing when they probably shouldn't) that something off the radar is going on here. The only way I'll be able to help with that is to see the actual database for myself. To attach a database you must follow these instructions carefully (Attach Database (or other work)). They're not rocket-science, but close following of them is often important.

                          Let me say that I'm pretty confident that a solution can be found, once we know what the problem actually is. Changing your tools because of a problem, rather than determining and then fixing it, is not an approach that I would ever recommend, as it's an attitude that ensures one never reaches a good understanding the subject. I applaud your decision to stick with it for now :-)

                          Comment

                          • wire
                            New Member
                            • Feb 2012
                            • 2

                            #14
                            On Access, the best I've been able to do is shorten the height of the sub-report and set the 'can grow' property to "yes". It still take a few millimeters of space but is better than otherwise using up the entire height of the fields.

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32634

                              #15
                              In that case I expect you'll be interested to see what we come up with. Even if it proves impossible it won't be uninteresting (but I'm pretty sure I've done something like this before successfully - though much of my more fiddly work has been in other people's projects so I don't have it to hand).

                              Comment

                              Working...