Share via

Highlighting a command button while hovering mouse on another

Anonymous
2016-06-28T20:10:21+00:00

Hello,

I have these command buttons with these captions:

  1. Products
  2. Customers
  3. Sales Invoive records.

I also have another set of command buttons with these captions:

  1. New Products
  2. New Customers and
  3. New Sales Invoies.

the first set is used to view their respective records according to their captions 

while the second set is also used to enter new records according their captions.

they are working very fine but I want the first set to be highlighted with say red color while I hover on the second set. For example, I want "Products" to change its back color to red while I hover on "new products" and so on.

Please help me on how to get this done

Thanks for all your assistance

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

Duane Hookom 26,825 Reputation points Volunteer Moderator
2016-06-30T11:49:13+00:00

You can try something like the following. I don't like the duplicated code but it should work.

Private Sub cmdNewCustomers_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Dim ctl As CommandButton

    Set ctl = Me(cmdNewCustomers.Tag)

    If ctl.ForeColor <> vbRed Then

        ctl.ForeColor = vbRed

    End If

End Sub

Private Sub cmdNewProducts_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Dim ctl As CommandButton

    Set ctl = Me(cmdNewProducts.Tag)

    If ctl.ForeColor <> vbRed Then

        ctl.ForeColor = vbRed

    End If

End Sub

Sub ResetButtonFore()

    Dim ctl As Control

    For Each ctl In Me.Controls

        If ctl.controlType = acCommandButton Then

            If ctl.ForeColor <> vbBlack Then

                ctl.ForeColor = vbBlack

            End If

        End If

    Next

End Sub

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    ResetButtonFore

End Sub

Was this answer helpful?

0 comments No comments

13 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-07-14T20:34:32+00:00

    Hello,

    I've got it working very fine now without any screen or control flickering.

    Thanks a lot for all your assistance.

    Was this answer helpful?

    0 comments No comments
  2. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2016-07-06T21:32:37+00:00

    I don't get any flicker using Access 2013. The colors are always correct. Do you have any space between the command buttons? Are the buttons in the detail section of the form?

    Maybe you should provide your entire code again since you have only posted partial code.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-07-06T00:49:26+00:00

    Yes, I added the code to call the function that resets the back color.

    The back color changes accordingly when I move from one Command Button to another. But The back colors only changes when I move the mouse on the free detail section of the form. But what I want is for the Back Colors to change and reset when I move from one command Button to another as I explained earlier. Again the the big issue is the flickering of the screen/controls with the application of the codes. How can I handle it?

    Was this answer helpful?

    0 comments No comments
  4. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2016-07-05T01:22:34+00:00

    You didn't at the code to call the reset code. 

    Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

        ResetButtonFore

    End Sub

    Was this answer helpful?

    0 comments No comments