Chapter 20: Advanced Access Report Techniques
741
Hiding forms during Print Preview
Very often, when you’re using the overlapping windows user interface in Access, a report opened
in Print Preview will be obscured by forms that are open on the screen. The easiest way to prevent
forms from getting in the way during Print Preview is to simply hide them as the report opens, and
then reveal them when the report is closed.
The RunReport() function opens a report for previewing and hides all open forms during Print
Preview. To restore the forms after previewing the report, set the report’s OnClose property to
=MakeFormsVisible(-1).
Function RunReport(RepName As String)
Dim intErrorCode As Integer
DoCmd.OpenReport RepName, acPreview
intErrorCode = MakeFormsVisible(False)
End Function
Function MakeFormsVisible (YesNoFlag As Boolean)
Dim intCounter As Integer
On Error GoTo HandleError
For intCounter = 0 To Forms.Count - 1
‘If you want to make sure a hidden form is not
‘displayed, use the forms(intCounter).formname
‘statement to get the form name.
Forms(intCounter).Visible = YesNoFlag
Next intCounter
ExitHere:
Exit Function
HandleError:
Msgbox “Error “ & Err.Number & “: “ & Err.Description
‘Make sure all forms are restored if an error occurs.
For intCounter = 0 To Forms.Count - 1
Forms(intCounter).Visible = True
Next
Resume ExitHere
End Function
Using snaking columns in a report
When the data displayed on a report doesn’t require the full width of the page, you may be able to
conserve the number of pages by printing the data as snaking columns, as in a dictionary or phone
book. Less space is wasted and fewer pages need to be printed, speeding the overall response of the
report. More information is available at a glance and many people find snaking columns more aes-
thetically pleasing than simple blocks of data.
For the examples in this section, I need a query that returns more data than I’ve been using up to
this point. Figure 20.32 shows the query used to prepare the sample reports in this section.