Have you ever needed to work with Conditional Formatting via VBA and tried to iterate through the FormatConditions collection?! Did you get incomplete results? Well, there is apparently a serious bug depending on the approach taken.
Note, this applies to Access 2016 and earlier, and per Karl’s comment below, has since been addressed in latter versions.
That being said, Microsoft did not push a fix for this bug to earlier versions. Thus, the workaround solution still remains the sole universal solution that will work properly on all versions of Access and as such, is the approach I recommend developers use.
The easiest approach to iterating over the collection is to do something like the following which is to iterate over the FormatConditions object:
Dim oFC As FormatCondition
Dim i As Long
For Each oFC In Me.FirstName.FormatConditions
i = i + 1
Debug.Print i, oFC.Expression1
Next oFC
Yet, this will fail to list more than 3 Format Conditions! Yep, you read that right. It will not necessarily list all the conditions. Making it worse, is I found no mention of this in the documentation (see below – maybe I missed it?!).
Continue reading →