Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Home > Courses > Access > Developer > D61 > Conditional Formatting on Focus by Michael Albert >
Back to Access Developer 61    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Conditional Formatting on Focus
Michael Albert 
       
3 days ago
When I tab through the controls on a form, when a certain control has focus, how do I change that control's color. When It has focus I want to grab the users attention. I've searched for everything I could think of and can't find anything useful.

Mike
Donald Blackwell  @Reply  
        
3 days ago
Richard Rost  @Reply  
          
3 days ago
Donald is right - Conditional Formatting is the easiest way to do this. Set a rule for "Field Has Focus" and choose the background color, font color, etc. you want for that control.

You can apply it to most text boxes, combo boxes, and similar controls without writing any VBA.
Michael Albert OP  @Reply  
       
2 days ago
Excellent, thanks guys.
Michael Albert OP  @Reply  
       
2 days ago
Sorry, the control in question is a button. Conditional Formatting not available.
Any other thoughts?

Kevin Robertson  @Reply  
           
2 days ago
Add this code to a Global Module.

DetailsPublic Function HighlightButton(ByVal HasFocus As Boolean)

    Static btn As CommandButton
    Static originalColor As Long
    Static originalTheme As Long
    Static originalTint As Single
    Static originalShade As Single
    Static originalGradient As Long

    If HasFocus Then
        Set btn = Screen.ActiveControl

        With btn
            originalColor = .BackColor
            originalTheme = .BackThemeColorIndex
            originalTint = .BackTint
            originalShade = .BackShade
            originalGradient = .Gradient

            .BackThemeColorIndex = -1
            .BackColor = RGB(255, 255, 0)
            .Gradient = 0
        End With

    ElseIf Not btn Is Nothing Then
        With btn
            .BackColor = originalColor

            If originalTheme <> -1 Then
                .BackThemeColorIndex = originalTheme
                .BackTint = originalTint
                .BackShade = originalShade
            End If

            'Restore this after the colour properties.
            .Gradient = originalGradient
        End With

        Set btn = Nothing
    End If

End Function


In the Property Sheet

On Got Focus
   =HighlightButton(True)

On Lost Focus
   =HighlightButton(False)
Richard Rost  @Reply  
          
2 days ago
For a button, you can use its On Got Focus and On Lost Focus events to change the BackColor with a little VBA. Just keep in mind that it only fires when the button receives focus, such as when the user tabs to it. Hovering the mouse over it is a separate option available in the button's formatting properties.

Also, this approach isn't suitable for a continuous form. Changing the color of a control there changes it for every displayed record, not just the current row.
Michael Albert OP  @Reply  
       
17 hours ago
Thanks guys, works like a charm.
Kevin Yip  @Reply  
     
16 hours ago
Some would prefer to have no tab stops for buttons ("Tab Stop" property set to No), and only tab stops for textboxes.  This is to make sure the user clicks the buttons with the mouse, without accidentally activating the buttons with the keyboard.  This is just a preference, of course, but something to think about.  To make buttons stand out on a form, you could use its various color properties: HoverColor, HoverForeColor, PressedColor, PressedForeColor, etc.
Michael Albert OP  @Reply  
       
8 minutes ago
Thanks Kevin.
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/25/2026 7:33:17 AM. PLT: 1s