Chapter 20: Advanced Access Report Techniques
733
The Format event occurs as Access begins to format the controls within the Detail section. The
value in txtCounter is incremented each time a record is added to the Detail section. The Mod
operator returns whatever number is left over when the value in txtCounter is divided by 5.
When txtCounter is evenly divisible by 5, the result of the txtCounter Mod 5 expression is 0 ,
which causes a space character to be assigned to txtSpacer. In this situation, because txt-
Spacer is no longer empty, Access increases the height of the Detail section to accommodate
txtSpacer, causing the “empty” space every fifth record to be printed in the Detail section. You
never actually see txtSpacer because all it contains is an empty space character.
txtCounter can be placed anywhere within the Detail section of the report. Make txtSpacer
as tall as you want the blank space to be when it’s revealed on the printout.
Even-odd page printing
If you’ve ever prepared a report for two-sided printing, you may have encountered the need for
knowing whether the data is being printed on the even side of the page or the odd side of the page.
Most users prefer the page number to be located near the outermost edge of the paper. On the
odd-numbered page, the page number should appear on the right edge of the page, while on the
even-numbered side, the page number must appear on the left side of the page. How, then, do you
move the page number from side to side?
The easiest way to determine whether the current page is even or odd is with the Mod operator
with the following small function:
Function IsEven(iTest As Integer) As Integer
If iTest Mod 2 = 0 Then
IsEven = True
Else
IsEven = False
End If
End Function
Assuming the page number appears in the Page Footer section of the report, you can use the page
footer’s Format event to determine whether the current page is even or odd, and move the text
box containing the page number to the left or right side of the page accordingly.
The basic design of rptEvenOdd is shown in Figure 20.27. Notice that the txtPageNumber is
right-aligned to ensure that the page number appears as close to the right margin as possible.