Share via

Can I use conditional formatting for when command button gets focus?

Anonymous
2013-07-09T15:56:23+00:00

I have a form with many fields, and as the user completes a field and presses Enter or Tab to move to the next field, they can usually see the cursor flashing in the field to indicate that's what has the focus. However, when a command button gets the focus, the only indication is that the button has a super fine line around the outside.

My users are mostly older people, many with vision limitations. Is there a way I can make this more obvious? I thought conditional formatting, but that seems rather convoluted.

Any suggestions are appreciated.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2013-07-09T19:22:27+00:00

Ken's suggestion can easily be expanded to work for any control that has the ForeColor property.  First create a function in a standard module (not a form's module):

Public Function Highlight(frm As Form, OnOff As Boolean)

Static PrevColor As Long

With frm.ActiveControl

If OnOff Then

   PrevColor = .ForeColor 

   .ForeColor = vbRed

   .FontBold = True

Else

   .ForeColor = PrevColor

   .FontBold = False

End If

End With

End Function

Then you need to set the OnGotFocus property of each control that can receive the focus (and has the ForeColor property) to =Highlight(Form, True) and the OnLostFocus property to =Highlight(Form, False)

That can be done wholesale by using Shift+Click on each control and then setting the properties for all of the selected controls in one shot.  You will have to repeat the selecting and setting properties for each form though.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2013-07-09T19:15:49+00:00

For text boxes and combo boxes, you can use conditional formatting to highlight them when they have the focus:

  • Select a bunch of text boxes and/or combo boxes.
  • On the Format tab of the ribbon, click Conditional Formatting.
  • Under Condition 1, select "Field Has Focus" from the dropdown.
  • Click the B for bold (you can also change the font color and/or the background color if you wish).
  • Click OK.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2013-07-09T18:33:43+00:00

    Thank you both, Hans and Ken!! These are both brilliant suggestions.

    My next question becomes...Is there any way to do this globally in the application, or even for each form? How great if the font of any control that has focus changed to Bold until focus is lost. It would be so much easier for older people to see.

    Sorry to be a pain, but great ideas can always be enhanced.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-07-09T17:27:45+00:00

    Another way would be to change the control's ForeColor property in its GotFocus event procedure, e.g.

        With Me.ActiveControl

            .ForeColor = vbRed

        End With

    and back again in its LostFocus event procedure, e.g.

        With Me.ActiveControl

            .ForeColor = vbBlack

        End With

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2013-07-09T16:13:46+00:00

    You could do the following:

    • Place a box (rectangle) around the command button.
    • Set its Border Width to for example 3 points, and its Border Color to for example red.
    • Set its Visible property to No.
    • Create event procedures for the On Got Focus and On Lost Focus events of the command button:

    Private Sub cmdMyButton_GotFocus()

        Me.rctBox.Visible = True

    End Sub

    Private Sub cmdMyButton_LostFocus()

        Me.rctBox.Visible = False

    End Sub

    where cmdMyButton is the name of the command button and rctBox is the name of the rectangle.

    Was this answer helpful?

    0 comments No comments