Conditionally change text color

AlaskanDad

Registered User.
Local time
Today, 23:29
Joined
Jun 20, 2000
Messages
39
I know how to change the color of currency based on Positive,Negative,Zero, and Null but how do you change the color of text based on some other criteria. Changing the .ForeColor parameter changes all of the records in the field for that control and that is not what I want.

For example, I want to see all last names that start with the letter B colored blue while all that start with R colored red.

I have been doing this kind of work for awhile and I am stumped.
 
have a question? -ask: 31419537
i will glad to answer


for A2000

Private Sub Form_Load()
Dim ctl As Control
Dim i As FormatCondition
'FormatConditions works only in form like "DataSheet" and for ListBox & Combobox & TextBox
'Then we must delete previous FormatConditions for each control
' Maybe User created other FormatCondition
For Each ctl In Me.Controls
If ctl.ControlType = acListBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acTextBox Then
For Each i In ctl.FormatConditions
i.Delete
Next
If ctl.NAME = "NAME_TXT" Then
With ctl.FormatConditions _
.Add(acExpression, , "Mid([NAME_TXT],1,1)='B'")
.BackColor = 15532031
.FontBold = True
.ForeColor = 16711680

End With
With ctl.FormatConditions _
.Add(acExpression, , "Mid([NAME_TXT],1,1)='R'")
.BackColor = 15532031
.FontBold = True
.ForeColor = 255
End With
ii = 1
End If
End If
Next
End Sub
 
Thanks for your response.

The only part of the code I don't understand is the FormatCondition line. Is that only for Access 2000? The 97 version doesn't seem to know anything about it.
 
Here is an example of a similar coding I used in a report, this set both the background and foreground colour depending on criterea.

<snip>
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

Const WHITE = 16777215
Const YELLOW = 65535
Const Ghost = 8388608
Const BLACK = 0

Me![Domain Name].ForeColor = BLACK
Me.IP_Address.ForeColor = BLACK

If Me.Decomissioned = -1 Then
Me![Domain Name].BackColor = YELLOW
Me.IP_Address.BackColor = YELLOW

ElseIf Me![Ghost] = -1 Then
Me![Domain Name].BackColor = Ghost
Me.IP_Address.BackColor = Ghost
Me![Domain Name].ForeColor = WHITE
Me.IP_Address.ForeColor = WHITE

Else
Me![Domain Name].BackColor = WHITE
Me.IP_Address.BackColor = WHITE
End If
End Sub
<snip>

HTH
Loz
 
If you're still looking for a solution to this one, I've got something which is almost the equivalent of conditional formatting and which works nicely in A97, if you would like a copy of the demo, please mail me and I'll send it by reply.

Mike
 
This is what I am hoping to do - I need to start programming. From the discussion above does it mean that if I am pulling data from another database I can use a query and some of the code listed above (which I have to figure out) so that any evaluations which come back coded AR (Action Required) can then be red in the report? I send .snp files to the account managers.
 

Users who are viewing this thread

Back
Top Bottom