Change the font color/background of a text box depending on value

B

bknight

I have a form with 24 text boxes, one of which calculates a value based on
the difference between another text box and the same text box in the previous
record.

My desire is to change that test box's [Text42] font color and background
color depending on what value is calculated.
 
J

John W. Vinson

I have a form with 24 text boxes, one of which calculates a value based on
the difference between another text box and the same text box in the previous
record.

My desire is to change that test box's [Text42] font color and background
color depending on what value is calculated.

If you have A2000 or later, open the form in design view, select the control
and select Format... Conditional Formatting from the menu.
 
B

bknight

I'm using 97.

John W. Vinson said:
I have a form with 24 text boxes, one of which calculates a value based on
the difference between another text box and the same text box in the previous
record.

My desire is to change that test box's [Text42] font color and background
color depending on what value is calculated.

If you have A2000 or later, open the form in design view, select the control
and select Format... Conditional Formatting from the menu.
 
B

bknight

Actually I do have 2000, but developed and wrote code in 97, so just kept it
there. However, I opened it(after conversion) and I don't see any
conditional formating option in the control. Did you mean a version after
2000? If not then where would the conditional formating be located. All I
see is the normal pallete.

John W. Vinson said:
I have a form with 24 text boxes, one of which calculates a value based on
the difference between another text box and the same text box in the previous
record.

My desire is to change that test box's [Text42] font color and background
color depending on what value is calculated.

If you have A2000 or later, open the form in design view, select the control
and select Format... Conditional Formatting from the menu.
 
B

bknight

I did figure it out this way:

in the OnLoad control I entered:

DoCmd.GoToRecord , , acLast

Dim intOSCChange As Integer

If Not IsNull(Me!Text42.Value) Then
intOSCChange = Me!Text42.Value
End If

If Abs(intOSCChange) < 5 Then
Select Case intOSCChange
Case Is < 0
Me.Text42.BackStyle = 1
Me!Text42.ForeColor = 255
Case Is > 0
Me.Text42.BackStyle = 1
Me!Text42.ForeColor = 65280
Case Is = 0
Me.Text42.BackStyle = 0
Me.Text42.ForeColor = 0
End Select
End If

Me.Repaint

The "key" was the value itself, as I had been trying to set the properties
from its value directly, instead of setting a variable to the value and
setting the properties with the variable value.
 
B

bknight

I had to add this bit of code to statements to handle naviagtion properties
setting.
ElseIf Abs(intOSCChange) >= 6 Then
Me.Text42.BackStyle = 0
Me.Text42.ForeColor = 0


bknight said:
I did figure it out this way:

in the OnLoad control I entered:

DoCmd.GoToRecord , , acLast

Dim intOSCChange As Integer

If Not IsNull(Me!Text42.Value) Then
intOSCChange = Me!Text42.Value
End If

If Abs(intOSCChange) < 5 Then
Select Case intOSCChange
Case Is < 0
Me.Text42.BackStyle = 1
Me!Text42.ForeColor = 255
Case Is > 0
Me.Text42.BackStyle = 1
Me!Text42.ForeColor = 65280
Case Is = 0
Me.Text42.BackStyle = 0
Me.Text42.ForeColor = 0
End Select
End If

Me.Repaint

The "key" was the value itself, as I had been trying to set the properties
from its value directly, instead of setting a variable to the value and
setting the properties with the variable value.


bknight said:
I have a form with 24 text boxes, one of which calculates a value based on
the difference between another text box and the same text box in the previous
record.

My desire is to change that test box's [Text42] font color and background
color depending on what value is calculated.
 
J

John W. Vinson

Actually I do have 2000, but developed and wrote code in 97, so just kept it
there. However, I opened it(after conversion) and I don't see any
conditional formating option in the control. Did you mean a version after
2000?

I guess it was added in 2002. Sorry for the confusion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top