Share this Page URL

Chapter 10. Presenting Data with Reports > Using a Section's Format Event - Pg. 376

Presenting Data with Reports 376 Conditional formatting in a report You can apply conditional formatting to a control on a report by using the Conditional Formatting dialog box, basing the formatting either on a value or on an expression. With the report open in Design view, select the control whose data you want to highlight, and then choose Conditional Formatting from the Format menu. For detailed information about how to fill in the Conditional Formatting dialog box, see Chapter 8. In the following set of steps, we'll use the TasksSubreport (part of the CampaignSummary report) to demonstrate how to use a section's Format event. Format data using a section's Format event 1. 2. 3. 4. In the Database window, click Reports, select TasksSubreport, and then click Design. Right-click the Detail section bar, and then click Properties. On the Event tab, click in the On Format event property box, select Event Procedure, and then click the Build button. Add the following code to the Format event procedure: If Me.StartDate > #1/1/2004# Then Me.txtTaskName.FontBold = True Me.txtTaskName.ForeColor = vbRed Else Me.txtTaskName.FontBold = False Me.txtTaskName.ForeColor = vbBlack End If With the If statement, we define the condition that for tasks with a start date later than 1/1/2004, the task name is displayed in boldface, red type. (The values vbRed and vbBlack are Visual Basic constants.) If the date doesn't meet that condition, the task's name is displayed with