Can conditional formating affect font color, too?

hirsp1

New member
Local time
Today, 14:47
Joined
Oct 5, 2000
Messages
6
I would like to be able to conditionally change the font color. Is this possible? If so, how?
 
Yes you can change the font colour based upon a condition. You would need to decide what would trigger that change in colour (what value in a field would do this) and what numbers represent the colours you want. Below is an example from a form (that I quickly put together and tested) that will display the language/mother tongue "French" in green and everything else in black.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [MotherTongue] = "French" Then
Me![txtMotherTongue].ForeColor = 123456
Else
Me![txtMotherTongue].ForeColor = 1
End If

End Sub

I hope this helps.

Rich



[This message has been edited by Rich@ITTC (edited 10-12-2000).]
 
Worked great...turned your help into a function and voila!
 
Help w/Conditional formatting

I have a report, based on a query. For each job number there are many records, but I only want the most recent to appear.

This is the code I'm using but it's not working. It's in the details section of the report.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'Interim will expire in the query name
'Resubmission date is the date field that I want evaluated.
If Me.Resubmissiondate = DMax("ResubmissionDate", "Interim will expire") Then
Me.ForeColor = vbYellow

Else
'Me.Resubmissiondate.FontBold = False
' Me.Resubmissiondate.ForeColor = vbBlack
Me.FontBold = True
End If

Help would be greatly appreciated.

End Sub
 
teiben, when you want to modify control properties conditionally, you need to always account for both the true and false answers. The way your code is written, your changes are cumulative. Therefore, assume that the condition is true for the first record. That will cause the foreground color to change to yellow. Then if the condition is false for the second record, the bold attribute is applied but the color stays yellow since you didn't change it. From this point on, the foreground will be yellow and it will be bold for the rest of the report.
 
Thanks Pat, but I thought I was with the else statement, the Me.FontBold = True

Is there a special way of writing the code for date fields?
How what I'm trying to do is make the most recent submission date turn red, else stay black. How would you go about his?
 
No you weren't, Bold and Yellow are different properties so they are not mutually exclusive.

On a continuous form, you would need to use ConditionalFormatting but otherwise you can use an If statement.

Code:
If Me.Resubmissiondate = DMax("ResubmissionDate", "Interim will expire") Then
    Me.Resubmissiondate.ForeColor = vbRed
Else
    Me.Resubmissiondate.ForeColor = vbBlack
End If

The above would make Resubmissiondate red or black depending on the result of the If.
 
Thanks, but I get a compile error; line two it stops at .forecolor . Any ideas :p
 
Is Resubmissiondate the name of the control? The .forecolor property is a property of a control. When you type "Me.Resubmission." you should see a list of properties appear. One of these properties should be ForeColor. In fact when you type "Me." you should get a list of fields, controls, and form properties and Resubmissiondate should be in the list.
 
Pat

Resubmissions date is the name of the field. When I type resubmission. the only thing that comes up is .value. SHould I be using the Text41. which is the name of the control on the report. If I do this .forecolor doesn't show up either
 
Type it in anyway
Me.Text41.ForeColor= vbRed or whatever colour you want.
not all the properties available for controls in Reports are listed by default, .Visible isn't either. There is a setting somewhere to list them all, I can't remember where though :o
 

Users who are viewing this thread

Back
Top Bottom