Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change font colour in txt box when equals different values

Status
Not open for further replies.

Robson8112

Technical User
Sep 5, 2002
39
GB
I need to be able to change the font colour of a txt box when it equals a certain value.

e.g if the value equals 1 (and above), the text is green
if the value is below 1 (-1 etc) the font colour changes to RED.

can anyone help?





 
Right click the field and select CONDITIONAL FORMATTING (in reports). you can go from there no problem.
 
Don't worry Robson - it works in Forms as well.

With the form in design mode click on the control (s) that you want to edit then from the Format menu choose Conditional Formatting.

Then fill in the dialog box just like you would on an Excel cell's conditional formatting.



'ope-that-'elps.

G LS
 
If you want to control more than three conditions you'll have to do it in VBCode.


G LS
 
Here's a routine that shows you how to set the BorderColor, BackColor & ForeColor properties depending on the value of the txtPastDue text box:


Sub Form_Current()
Dim curAmntDue As Currency, lngBlack As Long
Dim lngRed As Long, lngYellow As Long, lngWhite As Long

If Not IsNull(Me!txtPastDue.Value) Then
curAmntDue = Me!txtPastDue.Value
Else
Exit Sub
End If
lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)
If curAmntDue > 100 Then
Me!txtPastDue.BorderColor = lngRed
Me!txtPastDue.ForeColor = lngRed
Me!txtPastDue.BackColor = lngYellow
Else
Me!txtPastDue.BorderColor = lngBlack
Me!txtPastDue.ForeColor = lngBlack
Me!txtPastDue.BackColor = lngWhite
End If
End Sub


Hope that helps you.
 
Madhouse,

I have Access97, continuous forms....how would change the forecolor of textbox1 based on the value of textbox2?
 
All you would need to do is something like the following:

Sub Form_Current()
Dim lngRed As Long, lngBlack As Long

lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)

If Me!textbox2 = "Your Value" Then
Me!textbox1.ForeColor = lngRed
Else
Me!textbox1.ForeColor = lngBlack
End If
End Sub

 
And remember to call madhouse's Form_Current procedure from the textbox2_AfterUpdate event

And call it if you ever change the value of textbox2 in code.


G LS G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! :-D

 
I have a problem with this also. To make it simple, here is the scenario. I have 3 records, each one with an Identifier and a combobox field. The combobox options are Yes, No, NA. When showing these fields on a continuous form, how would I be able to have record #1 combobox field show red (for equalling "No"), record #2 combobox show green (for equalling "Yes") and record #3 combobox show white (for equalling "NA"). I have tried code very similar to the above, but when the records are changed through the combobox, all the comboboxes are changed to the colour of the last change regardless of what the value of the field is. Is there any way in Access to get around this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top