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

  • Thread starter Thread starter bknight
  • Start date Start date
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
Back
Top