- Do one of the following:
Base conditional formatting on the value of the control
The control's appearance changes if the value in the underlying field for that record meets criteria that you specify. For example, you can specify the UnitPrice field to be highlighted with a different color when it contains a value between $25.00 and $50.00. Also, you can specify an additional criteria to highlight the UnitPrice field with another color if it contains a value greater than $50.00.
To use values in the selected control as the formatting criteria, under Condition 1, click Field Value Is in the first box, click the comparison phrase in the second box, and then type a value in the third (and fourth) box. You can enter a constant value or an expression.
Base conditional formatting on an expression
You can also change the appearance of a control when an expression or a Visual Basic® for Applications (VBA) function returns a value of TRUE. For example, you might want the appearance of the ProductName field to match the appearance of the UnitPrice field. To change the format of the ProductName field to match the format of the UnitPrice field, use expressions in the conditional formatting criteria for the ProductName field that check the value of the UnitPrice field.
To use an expression as the formatting criteria (to evaluate data or a condition other than the values in selected controls), click Expression Is in the first box, and then enter the expression in the second box. The expression must return a logical value of TRUE or FALSE.
- Select the font style, color, or other formatting that you want to apply. Microsoft Access applies the selected formatting only if the control value meets the condition, or the expression returns a value of TRUE.
You can use conditional formatting to prevent users from making changes to a control, when a condition is true. Specify the criterion, and in the format section, click the Enabled button (the rightmost button in the Conditional Formatting dialog box) once.
- To add another condition, click Add, and then repeat steps 1 and 2.
You can make data entry easier by using conditional formatting to highlight the control that has the focus. When the control you're located in is highlighted, it's easier to work with a form that contains many controls, or with a continuous form or a datasheet form that contains many records.
- In the Condition x area of the Conditional Formatting dialog box, click Field Has Focus in the first box.
- Select the font style, color, or other formatting that you want the field to have when it has focus.
Note The procedure described above will highlight the specific control when it gets focus. When focus changes, the control that gets the focus will not appear highlighted unless you repeat the above two steps for that control. To apply conditional formatting to multiple controls, select them before you click Conditional Formatting on the Format menu, and then specify the criteria and format.