Conditional Formatting Question

T

TotallyConfused

Can you have more than 3 conditional via code and 3 conditions using CF? If
not then how many conditions can I have in all in a form/subform? I have
check forums and answers and can't find something that will help. I need to
be able to add one more condition via code. I just want to be able to on
checking checkbox make my other textboxes backcolor green. I need to see a
sample please.

If not how can I write an If expression in CF. For example "IF[field1] is
null and [field2] is null and if [field3] is null then "condition". Can
someone provide a sample? Thank you.
 
R

Rod Plastow

Now there is bad news and only bad news. Conditional formatting is available
for text boxes, combo boxes and forms only; it is not available for check
boxes. This rather makes your other questions somewhat redundant.

You could substitute the check box label with a text box and apply
conditional formatting to the text box such that its back color changes
according to the value of the corresponding check box.

As far as being able to apply more than three conditional formats to any
control, I've never tried. It's difficult to image the scenario where you
want to change all six properties for the same control. However in VBA the
conditions are in a collection and I assume you can have as many as you like.
(Anyone?)

Rod
 
T

TotallyConfused

Thank you for responding. I am aware that you can't apply conditional
formatting to checkboxes. What I want to do is if checkbox is true then my
other textboxes backcolor be yellow or blue or whatever. If checkbox is
false other textboxes would remain default color. I just need to know how to
write this in code. Thank you.
 
R

Rod Plastow

Sorry, should have read more closely. Wait ten while I get some code samples
for you.

Rod
 
R

Rod Plastow

Here's some working sample code from one of my applications (watch out that
this board tends to wrap text):

Private Sub Form_Load()

On Error GoTo Error_Handler

'Highlight changes in bold font.

Me.TxAmountNew.FormatConditions.Delete
Me.TxAmountNew.FormatConditions.Add acExpression, , "TxAmountOrig <>
TxAmountNew"
Me.TxAmountNew.FormatConditions(0).FontBold = True
Me.TxTextNew.FormatConditions.Delete
Me.TxTextNew.FormatConditions.Add acExpression, , "TxTextOrig <>
TxTextNew"
Me.TxTextNew.FormatConditions(0).FontBold = True

Exit_Procedure:

Exit Sub

Error_Handler:

FeRod.ReportError
Resume Exit_Procedure
Resume

End Sub

FormatConditions is a collection (?) and can be addressed by an index
relative to 0. I have found, generally, that format conditions are
persistent and once applied programmatically persist for the control until
changed. This means the code in the form's load event could be commented out
after the first iteration. However I have encountered cases where this is
not true so I leave the code active in all cases.

FormatConditions.Delete is benign, it won't raise an error if there are no
existing conditions. After deleting you know the first condition will be
index 0. I think the rest of the code is self explanatory.

Rod
 

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