Change BackColor of text box

B

Bret

Please help.
In my form text boxes, I have a function tied to the event
procedure that changes the 'BackColor' of the box based on
the a calculated percentage.
My fields fill in successfully but the textbox doesn't
change color. I've used the "repaint" code with no success.
The code is below. thanks.


Private Sub Text77_AfterUpdate()
Dim p As Variant
p = Me.Text82.Value
Text82.BackColor = Fill_AttainBackColor(p)
Me.Repaint
End Sub
Event Procedure above calls function below passing the
percentage contained in textbox.

Function Fill_AttainBackColor(p)

' Text54.BackColor = Fill_AttainBackColor(P)
Select Case p


Case Is <= 0.7999999999
Fill_AttainBackColor = 255
Case Is >= 80#, Is <= 0.9499999999
Fill_AttainBackColor = 8454143
Case Is >= 0.95
Fill_AttainBackColor = 65280
End Select

End Function
 
R

Rick B

Have you tried just using conditional formatting instead of code?

Rick B


Please help.
In my form text boxes, I have a function tied to the event
procedure that changes the 'BackColor' of the box based on
the a calculated percentage.
My fields fill in successfully but the textbox doesn't
change color. I've used the "repaint" code with no success.
The code is below. thanks.


Private Sub Text77_AfterUpdate()
Dim p As Variant
p = Me.Text82.Value
Text82.BackColor = Fill_AttainBackColor(p)
Me.Repaint
End Sub
Event Procedure above calls function below passing the
percentage contained in textbox.

Function Fill_AttainBackColor(p)

' Text54.BackColor = Fill_AttainBackColor(P)
Select Case p


Case Is <= 0.7999999999
Fill_AttainBackColor = 255
Case Is >= 80#, Is <= 0.9499999999
Fill_AttainBackColor = 8454143
Case Is >= 0.95
Fill_AttainBackColor = 65280
End Select

End Function
 
M

Marshall Barton

Bret said:
In my form text boxes, I have a function tied to the event
procedure that changes the 'BackColor' of the box based on
the a calculated percentage.
My fields fill in successfully but the textbox doesn't
change color. [snip]
' Text54.BackColor = Fill_AttainBackColor(P)
Select Case p
Case Is <= 0.7999999999
Fill_AttainBackColor = 255
Case Is >= 80#, Is <= 0.9499999999
Fill_AttainBackColor = 8454143
Case Is >= 0.95
Fill_AttainBackColor = 65280
End Select

End Function

The second case above will always succeed since one
condition or the other will always be true. Try writing it
this way:

Select Case p
Case Is < 0.8
Fill_AttainBackColor = 255
Case Is >= 0.95
Fill_AttainBackColor = 65280
Case Else
Fill_AttainBackColor = 8454143
End Select
 

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