Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Format Conditions Bug
Kevin Yip 
      
2 hours ago
I recently ran into a bug while using FormatConditions in VBA.  I'm using Microsoft Access 2024 64-bit, version 2605, build 16.0.20026.20076, which is dated around May 2026.  This is an age-old bug (from 10-20 years ago) that was supposedly fixed in the years since, as this Devhut article says:

     https://www.devhut.net/access-formatconditions-object-for-each-iteration-is-incorrect/

But I'm getting it right now, and I'm curious to see if others are getting it too in their latest or semi-latest Access builds.

To recreate this bug, create a form, create a textbox called Text1, and put in this procedure in the form's VBA module:

DetailsPrivate Sub Form_Open(Cancel As Integer)
    ' 9/5/26 Created for testing
    
    Dim i As Integer
    Me.Text1.FormatConditions.Delete
    
    For i = 0 To 5
        Me.Text1.FormatConditions.Add acExpression, , "1 = 1"
    Next i
    For i = 0 To 5
        Me.Text1.FormatConditions(i).BackColor = RGB(255, 255, 255)
        Me.Text1.FormatConditions(i).ForeColor = RGB(0, 0, 0)
    Next i
End Sub


A run-time error will occur at the line that accesses Me.Text1.FormatConditions(3), which is the 4th member of the FormatConditions collection.

The bug is this: VBA can only access up to 3 members, even when there are more than 3 members.

The workaround I found (which isn't mentioned in the Devhut article above) is bizarre: do not use spaces in the format condition's expression.

Instead of using spaces in "1 = 1":  
     Me.Text1.FormatConditions.Add acExpression, , "1 = 1"

Remove the spaces:
     Me.Text1.FormatConditions.Add acExpression, , "1=1"

And there is no more run-time error.

If spaces must be used, such as when using logical operators ("A=B And C=D"), my second workaround is this: enter the format conditions in the form's design mode's UI.  That would also allow you to access past 3 members in VBA.

If anyone could try this out, thank you in advance and please let me know any findings.
Donald Blackwell  @Reply  
       
2 hours ago
Just tested out on my beta machine.

Win 11 Insider
Access v 2609 Build 20430.20000

Got same error.
Richard Rost  @Reply  
          
2 hours ago
Thanks for testing that, Donald. So it isn't just Kevin's particular installation.

That's a wonderfully strange bug. The fact that whitespace in the expression changes whether Access can enumerate past the third FormatCondition strongly suggests the collection is being parsed or internally rebuilt incorrectly when the conditions are added through VBA. Entering the same conditions through the property sheet in design view apparently follows a different code path, which explains why that workaround works.

For anyone who needs more than three conditions, I would avoid relying on FormatConditions.Add for expressions containing spaces until Microsoft fixes this. Either remove unnecessary spaces from the expression, as Kevin discovered, or create the conditional formatting rules manually in design view and then modify them in VBA if necessary.

Nice catch, Kevin. This is exactly the kind of ancient Access gremlin that makes you wonder what other COBOL-era ghosts are still hiding in there.

I'll submit this to the Access Team.
Richard Rost  @Reply  
          
84 minutes ago
I did a little more digging, and you definitely found something here. I checked through the Access MVP discussions, and this exact issue was reported to Microsoft back in 2023. At the time, the Access team identified the same strange behavior with spaces in the FormatConditions expression and indicated that it would be fixed.

Since you've reproduced it in a current build, and Donald confirmed it in the 2609 beta build, it looks like either the original fix never fully made it out or the bug has resurfaced. I've submitted the details to the Access team for review. Thanks again for catching this and, especially, for tracking down that bizarre whitespace workaround. Nice detective work.
Kevin Yip OP  @Reply  
      
56 minutes ago
Thank you guys for the additional info.  I found some old forum posts (on other sites) saying this had already been fixed.  So it must have resurfaced in the years since.  I haven't found any recent posts talking about this, so I'm probably one of earliest person to notice this.

This is one issue with frequent updates: bugs are more likely to be created or re-created due to more frequent changes to the code.  In the old days, we had to wait years for Office to get an update and we had to put up with bugs for years.  But we wouldn't see situations like this because the code wouldn't be changed for years.
Alex Hedley  @Reply  
            
28 minutes ago
This is where adding a Test for this specific bug is a good idea so when you run regression it proves it has been fixed!
Add a Reply Upload an Image
Next Unseen

 
 
What's This?

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 9/5/2026 3:25:57 PM. PLT: 0s