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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Colors 1

Status
Not open for further replies.

jbento

Technical User
Jul 20, 2001
573
0
0
US
All,
I have a form with a combo box field, named: softcopy_hardcopy. I have the following values associated with that combo box field: Cancelled, Both, Hardcopy, Need Hardcopy, Need Softcopy, & Softcopy. I would like the Cancelled to change to red font and bold when selected, but the others would remain black.

The problem I have is when I choose Cancelled with the following code, it turns all of the records for that field red, no matter if it's Cancelled or not. I also have additional code for the "N/A" value, but I'm not concerned with that, because that is working ok. I tried some Else statements as well, but they did not work either. Here is the code I'm using:

Private Sub softcopy_hardcopy_AfterUpdate()

If softcopy_hardcopy = "Cancelled" Then
location_softcopy = "N/A"
location_hardcopy = "N/A"
End If

If softcopy_hardcopy = "Both" Then
softcopy_hardcopy.ForeColor = 0
End If

If softcopy_hardcopy = "Hardcopy" Then
softcopy_hardcopy.ForeColor = 0
End If

If softcopy_hardcopy = "Need Hardcopy" Then
softcopy_hardcopy.ForeColor = 0
End If

If softcopy_hardcopy = "Need Softcopy" Then
softcopy_hardcopy.ForeColor = 0
End If

If softcopy_hardcopy = "Softcopy" Then
softcopy_hardcopy.ForeColor = 0
End If

End Sub

Can someone please let me know what I am doing wrong?

It would surely be appreciated.

Thanks,



Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Hi,

Hopefully, you are using Access 2000 + or else this won't work.

Open the form in design view, click on/select softcopy_hardcopy, then from the menu select Format >> Conditional Formatting. Under Condition 1 select "Expession Is" Paste this into the text box to the right of it.

[softcopy_hardcopy]="Cancelled"

Click the Bold Icon and select Red from the Fill Color Icon (Bottom right of window). Example text should now be Bold/Red. Click Ok.

You can do this for up to 3 conditions per control that support conditional formatting.

Bill
 
billpower,
I will try this tomorrow and let you know if it works. Thanks so much for responding:)

HAVE A GREAT WEEKEND!!!!

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
billpower,
That worked BEAUTIFULLY!!!!! Thank you so much.

Is there anyway to see the code for that?

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Hi Jerome,

What I always do is use the Tag property of the controls that I want to Conditionally Format. In this example, each control tagged Condition1 will be formatted so, If softcopy_hardcopy = Cancelled, Forecolor = Red, If softcopy_hardcopy = Accepted, Forecolor = Blue, Else don't change the Control's Format.

Place this in the On Current event of your Form or Sub Form:

Dim ctl As Control
On Error Resume Next
For Each ctl In Me.Form.Controls
With ctl
If .Tag = "Condition1" Then
With Me.Form.Controls(ctl.Name).FormatConditions _
.Delete 'delete any previous formats
End With
With Me.Form.Controls(ctl.Name).FormatConditions _
.Add(acExpression, , "[softcopy_hardcopy] = 'Cancelled'")
.Bold = True
.ForeColor = 255 'red
End With
With Me.Form.Controls(ctl.Name).FormatConditions _
.Add(acExpression, , "[softcopy_hardcopy] = 'Accepted'")
.Italic = True
.ForeColor = 16711680 'blue
End With
End If
End With
Next ctl

Bill
 
Hi Jerome,

I made a slight error in my code yesterday. Format Conditions doesn't support the Font and Italic properties, have replaced them with the correct properties, FontBold and FontItalic:

Dim ctl As Control
On Error Resume Next
For Each ctl In Me.Form.Controls
With ctl
If .Tag = "Condition1" Then
With Me.Form.Controls(ctl.Name).FormatConditions _
.Delete
End With
With Me.Form.Controls(ctl.Name).FormatConditions _
.Add(acExpression, , "[softcopy_hardcopy] = 'Cancelled'")
.FontBold = True
.ForeColor = 255 'red
End With
With Me.Form.Controls(ctl.Name).FormatConditions _
.Add(acExpression, , "[softcopy_hardcopy] = 'Accepted'")
.FontBold = True
.FontItalic = True

.ForeColor = 16711680 'blue
End With
End If
End With
Next ctl

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top