Changing color when typing

rozolins

New member
Local time
Today, 07:25
Joined
Mar 30, 2009
Messages
4
hey everybody. please help me, i whant to know, if its posible - when i tipe in a field, the field to changes its color...? lets say, when the field is empty its red, and when there is something writen inside its green.

please help me, it whould be really helpfull , if you chould tell how to acomplish this :)
 
If you know some VBA you can use diffrent events to do this.

If you set the field's default color to red and in the GotFocus event put something like this:

Code:
Private Sub txt1_GotFocus()
    Me.txt1.BackColor = vbGreen
End Sub

To check that something was typed in the field you can use the LostFocus event:

Code:
Private Sub txt1_LostFocus()
     If IsNull(Me.txt1) Then
        Me.txt1.BackColor = vbRed
    End If
End Sub

Hope this helps.

JR
 
JR's code will work in a Single View form, but you'll also need to put it in the Form_Current event for it to persist as you move from record to record. For Datasheet and Continuous views you'll have to use Conditional Formatting.

In Design View, select the control (textbox) then goto

Format - Conditional Formatting

Under Condition1 select Expression Is

In the next box enter IsNull([TextboxName])

Now select the color formatting, such as a Red backcolor

Click on Add

Under Condition2 select Expression Is

In the next box enter Not IsNull([TextboxName])

Now select the color formatting for when the field has data, such as Green back color

Click on OK

This will also work in Single View, without any other code.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom