totn Access

MS Access 2007: Conditionally change the background color of a text box on a Continuous Form

This MSAccess tutorial explains how to conditionally change the background color of a text box on a continuous form in Access 2007 (with screenshots and step-by-step instructions).

Question: In Microsoft Access 2007, how can I change the background color of a text box containing a date value on a Continuous Form? I would like to set the color individually on each record.

For example, if I had a field called Expiration_Date, I would like to change the color of this field only on the records where the date is older than today. Can this be done?

Answer: This can be accomplished with Conditional Formatting.

To do this, open the form in design view. Right click on the text box that you wish to conditionally format. Select "Conditional Formatting" from the popup menu. In this example, we want to conditionally format the Expiration_Date.

Microsoft Access

A Conditional Formatting window should appear. Select "Field Value Is" from the Condition1 combo box. Select "less than" from the next combo box and enter the following formula in the third field:

Now()

Microsoft Access

Next, select the formatting that you'd like to apply when this condition is met. We've chosen to change the background color to red when the Expiration_Date is less than the current system date/time.

Click on the OK button.

Microsoft Access

Now, when you view your Continuous Form, the records whose Expiration_Date is older than the current system date/time will display a red background.

You can apply this technique to change the forecolor of the text field as well.