tech on the net
Home About Us Feedback Site Map

Microsoft

Access Excel Word

Database

SQL Oracle / PLSQL SQL Server MySQL MariaDB PostgreSQL

Web Development

HTML CSS Color Picker

Language

C Language

More

ASCII Table Linux UNIX Java Clipart Joke of the Moment
Share this page:

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

See solution in other versions of Access:

Question: In Microsoft Access 2003/XP/2000/97, how can I change the background color of text box when the text box value changes?

Answer: 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 look at an example.

Microsoft Access

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.

Microsoft Access

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.

Microsoft Access

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

Microsoft Access

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.

Microsoft Access

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.

Microsoft Access

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

Microsoft Access

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.

Microsoft Access

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

Microsoft Access

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