Part III: More-Advanced Access Techniques
734
FIGURE 20.27
txtPageNumber moves from the right edge of the paper to the left edge of the paper.
The Page Footer Format event procedure is a bit more involved than the IsEven function
shown earlier. Because the Page Number text box is rather wide (we don’t know how many pages
are in the report, so the extra width ensures that there’s adequate space in the box to accommodate
almost any number), simply moving the text box to the left margin leaves the text in the text box
too far to the right. You have to adjust the TextAlign property of txtPageNumber to shift the
page number all the way to the left side of the text box. ALIGN_LEFT and ALIGN_RIGHT are inte-
ger constants set at 1 and 3 , respectively, in the Declarations section of the report’s code module.
Sub PageFooter1_Format ()
If (Me.Page Mod 2) = 0 Then
txtPageNumber.Left = 0
txtPageNumber.TextAlign = ALIGN_LEFT
Else
txtPageNumber.Left = 3.5 * 1440
txtPageNumber.TextAlign = ALIGN_RIGHT
End If
End Sub
In this event procedure, any time the expression Me.Page Mod 2 is zero (meaning, the page num-
ber is even) the Left property of txtPageNumber is set to 0 and its TextAlign property is set
to ALIGN_LEFT (1). On odd-numbered pages, TextAlign is set to ALIGN_RIGHT (3).
Notice how the Left property of txtPageNumber is set on odd-numbered pages. The expres-
sion 3.5 * 1440 is used to determine the Left property’s setting. You may recall that, by default,
all positioning information in Access Basic is done using twips as the unit of measure. There are
1,440 twips in an inch (or 567 twips in a centimeter), so this expression moves txtPageNumber
to a position 3^1 ⁄ 2 inches from the left print margin on the page. (Obviously, the position will
depend on the width of the report.)
Like magic, this event procedure causes the Page Number text box to move from the right side on
odd-numbered pages to the left side on even-numbered pages (see Figure 20.28).