Use Conditional Formatting in Microsoft Access Forms with VBA
Question details
Apply background colors to an Access form control based on text contained in a field value.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A form displays concatenated status values, and the user wants Resolved values to appear green and Active values to appear yellow.
- Observed behavior
- The desired colors should be applied to the form control for each record, rather than to the recordset field.
Open the form in Design View and identify the name of the status field and its bound text box. The examples below use a field named Status and a text box named txtStatus; replace these names with your own.
Create conditional formatting rules for the status control
Use the form designer to color the control without writing VBA code.
Open the form in Design View and select the text box bound to the Status field.
On the Format tab, select Conditional Formatting, then New Rule. Choose an expression-based rule and enter InStr(1, Nz([Status], ""), "resolved", 1) > 0. Set the background color to green.
Select New Rule again and enter InStr(1, Nz([Status], ""), "active", 1) > 0. Set the background color to yellow.
Save the form and open it in Form View. Check records containing Resolved or Active to confirm that the text box displays the expected color.

Create the control's formatting rules with VBA
Use VBA when rules need to be created or updated programmatically.
Use WPS Office for compatible documents and spreadsheets
WPS Office is a free, lightweight alternative with a familiar interface for working with documents and spreadsheets. Its Microsoft Office format compatibility makes it easy to move existing files, although it does not replace Access form controls or fix Access VBA.

Frequently Asked Questions
Can I set a recordset field's background color directly?
No. A recordset field stores data; background color is a property of the form control displaying it. Apply conditional formatting to that control instead.
How can I match a status word inside a longer string?
In a conditional formatting expression, use InStr with a text comparison, such as InStr(1, Nz([Status], ""), "resolved", 1) > 0. Replace Status with your field name.
What happens if a value contains both Resolved and Active?
Both expressions can match. Open Conditional Formatting from the form's Format tab and arrange the rules so the intended color has priority.
Why does the VBA example delete existing rules?
Me.txtStatus.FormatConditions.Delete clears the control's rules before adding new ones, preventing duplicates when the form loads. Remove or adapt that line if other rules must be retained.




