MS Access: Change the background color of a text box when the text box value changes in Access 2003/XP/2000/97

You need to create code that is triggered when the value of the text box changes and then change the background color accordingly.

Let's take a look at an example.


In this example, we have a form called Suppliers. We want to change the background color of the ContactTitle text box when the user changes the value in this text box.


First, you want to view the properties for the Form. Select the property called "On Current". A button with three dots should appear to the right. Click on the button.


When the Choose Builder window appears, highlight "Code Builder" and click on the OK button.


Next, we want to enter the following code:

ContactTitle.BackColor = vbWhite

The purpose of this code is to change the background color of the ContactTitle field to white whenever the user selects a record to view. We place this code on the Form's On Current event so that when you scroll through the records in the Supplier form, the ContactTitle field will reformat itself.

You can close down the Microsoft Visual Basic window.


Next, you need to place similar code on the text box's After Update event.


To do this, select the properties for the ContactTitle text box. Click on the property called "After Update". A button with three dots should appear to the right. Click on the button.


When the Choose Builder window appears, highlight "Code Builder" and click on the OK button.


Now, we want to enter code on this event:

ContactTitle.BackColor = vbRed

We place this code on the text box's After Update event so that once a user changes the value in the ContactTitle field, the text box will change its background color to red.


When we take a look at our form, we see that the background color for the ContactTitle field is white, by default.


Once a user changes the value in the Contact Title field, the background color will change to red.