coloured fields

bone head

Registered User.
Local time
Today, 22:57
Joined
Feb 11, 2002
Messages
73
I saw a database recently which had a feild which was filled red while empty and changed to green once data had been entered.

I would fvery much like to create a similar effect to indicate the status of something.

I am sure this is quite simple, however apparently not to me.

any help most welcome.
 
Here's the code you need:

Private Sub txtBal_AfterUpdate()

If IsNull(Me!txtBal) Then
Me!txtBal.BackColor = vbRed
Else
Me!txtBal.BackColor = vbGreen
End If
End Sub

If you want the background to start off red and change green when a value is entered, you just need to change the background colour of the field in design view to red.
 
If you are using Access 2K or XP you could do this using conditional formatting.

Select the field that you wish to set the back colour of and use Format >> Conditional Formatting .

You will need to add two conditions as follows:

Condition 1 >> Expression Is >> [FieldName] Is Null. Set the Back colour to "Red"

Condition 2 >> Expression Is >> [FieldName] Is Not Null. Set the Back colour to "Green".

To do this using code you will need to attach the code to the On Current event of the form and to the After Update event of the field:

Code:
Private Sub Form_Current()

    If IsNull(Me.YourFieldName) Or Me.YourFieldName = "" Then
        Me.YourFieldName.BackColor = vbRed
    Else
        Me.YourFieldName.BackColor = vbGreen
    End If
    
End Sub
The same code is attached to the After Update.

HTH

Graham
 
Formatting Text Box in Subform?

Is it possible to use similar coding to change the font color of a field in datasheet view in a subform based on the value of another text box in the same subform? Here is what I am trying to do. When the user pulls up his records, the subform list all of the training documents assigned to him. If the DateCompleted field is Null, I want the DocumentNumber field to be in Red.
Can this not be done in datasheet view?

Any help would be appreciated.

Thanks,

Toni
 
Thanks for the fast response, Pat. I have tried to use the conditional formatting option, but it does not seem to allow me to change the formatting of one text box based on another. I can only seem to change the color of the one text box. I have tried to use "Expression Is" with no luck. Is this what I should be using?

Thanks again,

Toni
 

Users who are viewing this thread

Back
Top Bottom