Results 1 to 4 of 4
  1. #1
    Treeivery is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2016
    Posts
    10

    Change field color on form using "On Got Focus" and "On Lost Focus"

    I've got a data entry form for end users that I would like to enhance with some code to change the color of fields when the user tabs to or places cursor.
    I've successfully used code in one database that I found at http://www.allenbrowne.com/highlight.html. However, the code is not working or a second database that I tried.


    Treeivery

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    'on got focus
    txtBox.backcolor = vbyellow

    'on lost focus
    txtBox.backcolor = vbWhite

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    No code required if you use conditional formatting
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    wvmitchell is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2020
    Posts
    24
    I have a sub in the code-behind for the form:

    Private Sub Highlight()
    On Error Resume Next
    Me.ActiveControl.BackColor = vbYellow
    Screen.PreviousControl.BackColor = vbWhite
    End Sub

    and then I add the GotFocus event to every control on the form that is Enabled; like this:

    Private Sub txtFees_GotFocus()
    Highlight
    End Sub

    You just have to make sure that the BackStyle property is set to Normal, not Transparent.

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

Similar Threads

  1. Replies: 4
    Last Post: 11-14-2019, 11:30 AM
  2. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  3. Control "what gets the focus" when a form opens?
    By GraeagleBill in forum Forms
    Replies: 3
    Last Post: 12-26-2014, 10:41 PM
  4. how to change focus of "next record" button
    By Andyatwork in forum Forms
    Replies: 2
    Last Post: 09-05-2012, 04:34 AM
  5. "On Change," On Focus"
    By ericsmith in forum Access
    Replies: 0
    Last Post: 03-28-2011, 01:02 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