Hi, and Welcome to Bytes!
In VBA boolean values are represented by the constants True and False, not Yes and No (which are treated as the names of variables - undeclared ones in this case). Rewriting your IIF using True to replace Yes and bracketing to make clear which part is which:
- Me.lblARF.ForeColor = IIf(((Me.ARF_HYPO = True) Or (Me.ARF_NEW_OLI = True) Or (Me.ARF_AMINO_USE = True)), vbRed, vbBlack)
However, as the checkboxes return True or False we don't need to compare those to True at all:
- Me.lblARF.ForeColor = IIf((Me.ARF_HYPO Or Me.ARF_NEW_OLI Or Me.ARF_AMINO_USE), vbRed, vbBlack)
In VBA it is stylistically better not to use in-line IFs at all, so how's about using
- IF (Me.ARF_HYPO Or Me.ARF_NEW_OLI Or Me.ARF_AMINO_USE) THEN
-
Me.lblARF.ForeColor = vbRed
-
ELSE
-
Me.lblARF.ForeColor = vbBlack
-
END IF
If you want to do away with repeatedly referring to the control for the forecolor property you could use a With statement as follows:
- With Me.lblARF
-
IF (Me.ARF_HYPO Or Me.ARF_NEW_OLI Or Me.ARF_AMINO_USE) THEN
-
.ForeColor = vbRed
-
ELSE
-
.ForeColor = vbBlack
-
END IF
-
END WITH
Finally, instead of placing the code in each event make it a private procedure and call that from each of the other event procedures - the After Update events for each of the controls (instead of On Click), and the Form Current event for the form itself.
-Stewart
ps should you find references to them at some stage the VB constants vbYes and vbNo are used for message boxes etc and are NOT synonyms for the boolean values True and False.