Conditional formatting based on the value of another field

R

RSunday

I have a report listing records. I would like the text part of a record to
change font color based on the value in another field of the same record.

How do I do that?
 
J

John Spencer

What do you mean by the Text part? Are you referring to another textbox
control or are you referring to a label?

You can use conditional formatting on textbox controls, but not on label controls.

Guessing that you mean a text box control, then click on it, select
conditional formatting and use the Expression is option

Set your expression to something like

[AnotherField] = "My value"

Then set up you font color change.

If you need to do this with a label, you can convert the label to a textbox
control and set its control source to something like
="This is my label"

Or you can use VBA to change the font color of the label in the format event
of the section that contains the label

IF [AnotherField] = "My value" Then
ME.SomeLabel.ForeColor = vbRed
ELSE
ME.SomeLabel.ForeColor = vbBlack
END IF


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
R

RSunday

You guessed right! And solved my problem. Thanks!

John Spencer said:
What do you mean by the Text part? Are you referring to another textbox
control or are you referring to a label?

You can use conditional formatting on textbox controls, but not on label controls.

Guessing that you mean a text box control, then click on it, select
conditional formatting and use the Expression is option

Set your expression to something like

[AnotherField] = "My value"

Then set up you font color change.

If you need to do this with a label, you can convert the label to a textbox
control and set its control source to something like
="This is my label"

Or you can use VBA to change the font color of the label in the format event
of the section that contains the label

IF [AnotherField] = "My value" Then
ME.SomeLabel.ForeColor = vbRed
ELSE
ME.SomeLabel.ForeColor = vbBlack
END IF


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I have a report listing records. I would like the text part of a record to
change font color based on the value in another field of the same record.

How do I do that?
 
Joined
Jan 26, 2021
Messages
1
Reaction score
0
What do you mean by the Text part? Are you referring to another textbox
control or are you referring to a label?

You can use conditional formatting on textbox controls, but not on label controls.

Guessing that you mean a text box control, then click on it, select
conditional formatting and use the Expression is option

Set your expression to something like

[AnotherField] = "My value"

Then set up you font color change.

If you need to do this with a label, you can convert the label to a textbox
control and set its control source to something like
="This is my label"

Or you can use VBA to change the font color of the label in the format event
of the section that contains the label

IF [AnotherField] = "My value" Then
ME.SomeLabel.ForeColor = vbRed
ELSE
ME.SomeLabel.ForeColor = vbBlack
END IF


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Thank you John! Really Easy!
 

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