Results 1 to 8 of 8
  1. #1
    lefty2cox is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    May 2013
    Posts
    163

    Back Color of Text Box With Focus


    Is there a property in the property sheet for the back color of a text box when the box has the focus or should I set that in VBA? I would have thought there would be a property in the property sheet. If it's not, and it is a VBA thing, what is the name of the property?

    Am I classifying that event correctly? Focus? I'm referring to when the curser is in the text box and actually entering data.

    Thanks.

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    I think you just have to use the GotFocus and LostFocus events and set it in VBA

    Code:
    Private Sub Textbox_GotFocus()
        Me.Textbox.BackColor = RGB(255, 0, 0) 'red
    End Sub
    
    Private Sub Textbox_LostFocus()
        Me.Textbox.BackColor = RGB(255, 255, 255) 'white
    End Sub
    You may also have to go ahead and reset it in the form's OnCurrent event to avoid unexpected behavior.

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Command buttons have additional properties for e.g. Hover fore colour and Pressed fore colour but this isn't available for textboxes.
    Its easy enough to handle using code as already suggested
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    lefty2cox is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    May 2013
    Posts
    163
    Thank you for that. While I was implementing it, I realized something. I'm sure that there is a better way to do what I'm doing but since I'm just displaying info in this form, I went ahead and set the "enabled" property of the text boxes to "no". This gives me the result I was looking for since I was trying to get rid of the white box on the first field that got focus. But I do appreciate the help because I'm learn every single time someone responds to my posts.

  5. #5
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    For a textbox, better use the Conditional Formatting and choose "Field Has Focus" from available options of relevant dropdown. Choose the format that you want and click OK.

  6. #6
    lefty2cox is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    May 2013
    Posts
    163
    Quote Originally Posted by accesstos View Post
    For a textbox, better use the Conditional Formatting and choose "Field Has Focus" from available options of relevant dropdown. Choose the format that you want and click OK.
    I didn't even though that existed. Looked for it after reading your post. Thanks for that.

  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 keep in mind, in following accesstos' advice, that you don't have to do this to each Control, one at a time. You can do it to all the desired Controls in one fell swoop:

    In Form Design View

    1. Hold down <Shift> and Left Click on each Control in turn.
    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. Under Condition1 use the Down Arrow to select FieldHasFocus
    5. Select the Fill/Back Color Desired
    6. 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

  8. #8
    lefty2cox is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    May 2013
    Posts
    163
    I will. Thank you.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2020, 07:13 AM
  2. changing background color on Focus
    By swenger in forum Forms
    Replies: 6
    Last Post: 09-25-2016, 09:55 AM
  3. Conditional back color of box.
    By BatmanMR287 in forum Reports
    Replies: 3
    Last Post: 07-12-2015, 02:39 PM
  4. Bring back focus to a form
    By AbbHeDa in forum Programming
    Replies: 6
    Last Post: 04-28-2012, 01:50 AM
  5. Replies: 2
    Last Post: 03-10-2009, 05:14 PM

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