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 
Conditional Formatting in VBA
Sami Shamma 
             
3 years ago
Greetings
I have a Conditional formatting on a Form that I would like to turn on or off based on a value in a DefalatT. Is there a code in VBA that will do that?

I attempted to use FieldName.FormatConditions but could not find help online on how it will work for what I want.

Thanks
Adam Schwanz  @Reply  
           
3 years ago
What is the conditional formatting doing? If it's just changing colors, could you just use backcolor with an if statement?

Something like
If DLookupValue = True then
FieldName.BackColor=RGB(255,0,0)
End If
Sami Shamma OP  @Reply  
             
3 years ago
Hi Adam
i have a conditional formatting set up like this
Sami Shamma OP  @Reply  
             
3 years ago

Sami Shamma OP  @Reply  
             
3 years ago

Sami Shamma OP  @Reply  
             
3 years ago
I was hoping to just issue a command like control.condition True. I guess I can abandon the Access conditional formatting all together and build it in VBA on my own.
Sami Shamma OP  @Reply  
             
3 years ago
I just realized it is really difficult to do that in VBA
Kevin Yip  @Reply  
     
3 years ago
Hi Sami, you could write a custom function that would return whatever you need, and use it inside the format condition.  For instance, a custom function could be:

     Function MyFunction1(ByVal num As Long) As String
         ...
         MyFunction1 = SomeValue
     End Function

And the format condition would be as pictured below.  A value from each row would be passed to the function, which would return a value pertaining to that row.
Sami Shamma OP  @Reply  
             
3 years ago
Thank you Kevin

I will try this and let you know
Sami Shamma OP  @Reply  
             
3 years ago
Hi Kevin

I finally have time to make this work, but I am stuck.
I have a Field on my DefaultT ShowColor Y/N
it is also on my MainMenu which is always open.

I am struggling to write the function you suggested on two fronts:
1) where to place it so it can pick up my ReligionCode.
2) what is the value the function should return so I can use it in my conditional Formatting "Expression is".

Thank you for your help.

PS. Can the "Expression is" take "AND" ?
Sami Shamma OP  @Reply  
             
3 years ago
Hi Kevin

I got is working with this:

TempVars("ColorOn")=True And [ReligionCode]='47'
in the Expression is

many thanks
Sami Shamma OP  @Reply  
             
3 years ago
I got it working with*

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

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: 8/7/2026 6:14:04 PM. PLT: 1s