To create an event procedure that is executed when the Format event occurs, set the OnFormat property to [Event Procedure], and click the Build button.
Private Sub sectionname_Format (Cancel As Integer, FormatCount As Integer)
The Format event procedure uses the following arguments.
Argument |
Description |
sectionname |
A string that is the name of the section affected by the Format event procedure. |
Cancel |
The setting determines if the formatting of the section occurs. Setting the Cancel argument to True (-1) cancels formatting of the section. |
FormatCount |
An integer value that specifies whether the Format event has occurred more than once for a section. For example, if a section doesn’t fit on one page and part of it moves to the next page of the report, the FormatCount argument is set to 2. |
If you cancel formatting, Microsoft Access doesn’t format the section for printing and prints the next section instead. You can use this event procedure to skip a section in a report without leaving a blank space on the page when the report is printed.
Format Event — Macros.
This example displays or hides a congratulatory message next to a calculated control that shows sales totals by salesperson. In report sections where the sales total is greater than the sales goal, a label named Message displays the message “Congratulations! You have met your sales goal” before the section is printed; in sections where the sales total is less than the sales goal, the label is hidden.
To try the following example, add the following code to a report that contains a label called Message and a text box called GrandTotal.
Private Sub SalesDetail_Format (Cancel As Integer, _ FormatCount As Integer) Const conSalesGoal = 1000 If Me!GrandTotal > conSalesGoal Then Me!Message.Visible = True Else Me!Message.Visible = False End IfSub