Results 1 to 7 of 7
  1. #1
    swenger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    151

    changing background color on Focus


    Is there a way with VBA to change the background of a field when it gets the focus and then change it back on lose focus. It didn't list backcolor from the available properties on GotFocus.

    I am trying to let the use know which field they are on as it is not always obvious.

    Thanks,

    Sam

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Check out Conditional Formatting on the ribbon.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Got focus has no properties - it is an event. For any object which has the backcolor property, you would need to use the GotFocus/LostFocus events, such as
    Private Sub txAmt_GotFocus()
    Me.txtAmount.Backcolor =
    End Sub

    What you'd put for the color would be one of the vb color constants, hexidecimal value (e.g. #FFFFFF) or perhaps one of the windows system color constants, but I've never used those in code. Use the LostFocus event to return the color to normal.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    I use this page to help with color values, has lots of options:

    http://www.endprod.com/colors/

  5. #5
    swenger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    151
    This solves my issue. Wasn't aware conditional formatting had focus option.

    Thanks,

    Sam

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problem. It's a lot easier than adding code to every control's got/lost focus events.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    And you don't have to do this for each Control one at a time...you can set the Conditional Formatting on all Controls in one fell swoop! In Form Design View

    1. Hold down <Shift> and Left Click on each Control in turn, to be formatted.
    2. In pre-2007, on the Menu go to Format - Conditional Format
    3. In 2007 and later, on the Ribbon, click on the Design Tab, then Click on the Conditional Icon
    4. Select the Field Has Focus Condition
    5. Click OK

    You're done!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-06-2016, 10:36 AM
  2. Replies: 5
    Last Post: 08-26-2013, 01:26 PM
  3. Replies: 5
    Last Post: 06-28-2013, 06:11 PM
  4. Replies: 3
    Last Post: 04-28-2013, 04:10 PM
  5. Background Color
    By Meccer in forum Access
    Replies: 4
    Last Post: 05-30-2011, 06:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums