FormatCount Property

Microsoft Access Visual Basic

property has been evaluated for the current section on a report. Read/write Integer.

expression.FormatCount

expression    Required. An expression that returns one of the objects in the Applies To list.

Remarks

You can use this property only in a macro or an Visual Basic event procedure specified by a section's OnFormat property setting.

This property isn't available in report Design view.

Microsoft Access increments the FormatCount property each time the OnFormat property setting is evaluated for the current section. As the next section is formatted, Microsoft Access resets the FormatCount property to 1.

Under some circumstances, Microsoft Access formats a section more than once. For example, you might design a report in which the KeepTogether property for the detail section is set to Yes. When Microsoft Access reaches the bottom of a page, it formats the current detail section once to see if it will fit. If it doesn't fit, Microsoft Access moves to the next page and formats the detail section again. In this case, the setting for the FormatCount property for the detail section is 2 because it was formatted twice before it was printed.

You can use the FormatCount property to ensure that an operation that affects formatting gets executed only once for a section.

Example

In the following example, the DLookup function is evaluated only when the FormatCount property is set to 1:

Private Sub Detail_Format(Cancel As Integer, _
     FormatCount As Integer)
    Const conBold = 700
    Const conNormal = 400
    If FormatCount = 1 Then
        If DLookup("CompanyName", _
                "Customers", "CustomerID = Reports!" _
                & "[Customer Labels]!CustomerID") _
                Like "B*" Then
            CompanyNameLine.FontWeight = conBold
        Else
            CompanyNameLine.FontWeight = conNormal
        End If
    End If
End Sub