Question

I need to conditional format 24 text boxes with 2 rules each. Each rule is slightly different, based on the month. Is there some way I can type my conditional format rules all in one screen so I don't have to click so many buttons? Plus, this would save considerable time if I even needed to edit the rules. Psuedocode:

Style1 = FontFill.Red
Style2 = FontFill.Yellow

txtField1.ConditionalFormatting.Add("<rule text>", Style1)
txtField1.ConditionalFormatting.Add("<rule text>", Style2)

txtField2.ConditionalFormatting.Add("<rule text>", Style1)
txtField2.ConditionalFormatting.Add("<rule text>", Style2)
Was it helpful?

Solution

You can use the FormatConditions.Add Method in place of your pseudo code. With "Form3" open in Design View, I did the following in the Immediate window:

Forms("Form3").Controls("txtNote").FormatConditions.Add acFieldValue, acBetween, 10, 100
Forms("Form3").Controls("txtNote").FormatConditions(0).ForeColor = vbRed
' confirm the FormatCondition is enabled ...
? Forms("Form3").Controls("txtNote").FormatConditions(0).Enabled
True

Then inspecting the format condition from the form property gave me this ...

Conditional Formatting screen shot

For 24 controls, you could create a procedure to apply the conditional formats. Modify the procedure when the rules change. Or store the rules in a table and have the procedure read the rules from the table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top