[ Team LiB ] |
Recipe 3.10 Print Different Headers or Footers on Odd and Even Pages3.10.1 ProblemSome of your reports are printed double-sided, and you would like to have mirror-image headers and footers on odd and even pages. How do you do this in Access? 3.10.2 SolutionThis technique makes use of two sets of header and footer controls, one for odd pages and one for even pages. An event procedure run from the section's Format event uses the Page property and the Mod operator to determine whether the page is odd or even and makes the appropriate controls visible or invisible. The following steps show you how to create your own report that prints different headers and footers on odd and even pages:
Figure 3-22. rptEvenOdd in design viewTo see the sample report, load 03-10.MDB. Open rptEvenOdd in print preview mode; you should get a report that has one header and footer for odd pages (see Figure 3-23) and a different header and footer for even pages (see Figure 3-24). Figure 3-23. The footer for the odd pages of rptEvenOddFigure 3-24. The footer for the even pages of rptEvenOdd3.10.3 DiscussionThe two event procedures call the acbIsEven function to determine whether the current page is even or odd, passing the current page number to the function. The current page number is determined by referencing the Page property of the report (Me.Page). acbIsEven uses the Mod operator, which returns the remainder when the page number is divided by 2, yielding 0 for even pages or 1 for odd pages. The following statement: acbIsEven = ((intValue Mod 2) = 0) returns True to the calling procedure if the page Mod 2 is 0 (i.e., if the page is even); otherwise, it returns False. If you set fIsEven to the return value of acbIsEven, you can then set the visibility of the rest of the controls based on its value. You can't see them in Figure 3-22, but there are four text boxes in the footer section of the example report. On the left side of the footer, the txtPagePrintedOnLeft control has been placed on top of the txtPageLeft control. On the right side of the footer, the txtPageRight control has been placed on top of the txtPrintedOnRight control. This works because only one set of controls (txtPagePrintedOnLeft and txtPageRight, or txtPageOnRight and txtPageLeft) are visible at the same time. As an alternative to using two controls in the header of the report, you could use just one control that is as wide as the report and alternately set its TextAlign property to Left or Right based on the return value of acbIsEven. (You can't do this in the footer because of the need for two sets of controls with different alignments.) |
[ Team LiB ] |