Share via

Conditional Page Break

Anonymous
2013-03-12T23:19:51+00:00

I've been using Access for about 15 years, but till now I've been happy with the normal page break features that I can set with various header and foot properties.  Now I've got an odd one.  I have a report that prints fact sheets (actually it print a data dictionary for a logical data model).  There are a few hundred of these fact sheets.  Most of them are 1-page.  A few are more than one page.  The most is three.  About 30% are less than half a page.  Right now I force a page break before each sheet.  This wastes paper.  I'd like to add some logic so that when two short pages come one after another they both print on the same page.  What I wan't to avoid is having the second sheet start on one page and tumble to the next simply because it started on the bottom half of a page.

I'm comfortable working in Visual Basic and using events.  I'm about to do some experimenting to see if I can discover a way to do this, but I thought I'd ask for help first.

TIA

Rich

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2013-03-14T03:16:54+00:00

    Everyone,

    I've done some experimenting.  The PageBreak can be turned on and off in VB handler for the ONFORMAT event, but I knew that.  I developed some logic that would tell how much space a section required.  I used the .top property of the section to get its top and I created a dummy section footer so I could use the .top of that to get the bottom.  (My section has two subforms that can both grow quite a bit.)  Now I know how much space a section needs.  I can do this again for the next section and if that section is small enough I can turn off the PageBreak.  But at this point it's too late because the second section has already been formatted!

    I was about to write some code to format the report in two passes with the first pass recording the section sizes and the second pass controlling the PageBreak.  I think I could have made that work.

    HOWEVER: Then I thought, wouldn't it be nice if the Keep Together property would work with both the section header and the detail section.  But it doesn't, it only applies to a single section.  Now my report had a header section and a detail section, but the detail section in this report does not repeat. That's because there are two repeating groups which require two subforms.  For this reason, I didn't need a header section.  So I moved all the header fields into the detail section.  Now Keep Together does just what I want and I don't have to experiment with VB for now.

    It would seem the solution is to use a sub report instead of a repeating detail section and use the Keep Together property of the detail section to get the page breaks to work as I wish.  I have no problem with sub reports, but it seems a little kludgy.  On the other hand, it does what I want and it's a lot less kludgy than my two-pass approach.

    Rich

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-03-13T21:34:03+00:00

    Tom,

    Thanks for the reply.  I'm planning to experiment with the PageBreak control.  My problem is that I've never tried to force reformatting under program control using VB.  I'm also not sure of the best way to tell if the second page is small enough to fit with the page ahead of it.  When I learn more, I'll post a following-up.  Meanwhile, if anyone has additional advice of things to try or avoid, I'd appreciate it.

    Rich

    Was this answer helpful?

    0 comments No comments
  3. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2013-03-13T03:45:10+00:00

    You could experiment with the PageBreak control which is available when designing reports. If it is hidden, it does not apply; otherwise it forces a page break. You may want to write the code to show/hide it in the OnFormat event.

    Was this answer helpful?

    0 comments No comments