Chapter 20: Advanced Access Report Techniques
727
FIGURE 20.22
rptPriceList in Design view reveals how this effect is implemented.
Use the Detail section’s Format event to switch the Visible property of txtMessage to True
whenever txtDiscontinued contains a true value. The code is quite simple:
Private Sub Detail_Format(Cancel As Integer,
FormatCount As Integer)
If Me![Discontinued] Then
Me!txtProductName.FontItalic = True
Me!txtPrice.FontItalic = True
Me!txtPrice.FontBold = True
Me!txtPrice = Me![UnitPrice] * 0.5
Me!txtMessage.Visible = True
Else
Me!txtProductName.FontItalic = False
Me!txtPrice.FontItalic = False
Me!txtPrice.FontBold = False
Me!txtPrice = Me![UnitPrice]
Me!txtMessage.Visible = False
End If
End Sub
In this code fragment, Me is a shortcut reference to the report. You must explicitly turn the italics,
bold, and other font characteristics off when the product is not discontinued. Otherwise, once a
discontinued product has been printed, all products following the discontinued product will print
with the special font attributes. The font characteristics you set in a control’s Property Sheet are
just the initial settings for the control. If you change any of those properties at runtime, they stay
changed until modified again. Similarly, txtMessage must be hidden after it’s been displayed by
setting its Visible property to False.