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-03T11:13:57+00:00

    Thanks a lot.

    I have been able to edit and apply the code repeatedly on each of the command Buttonns' mouse event and it changes the back color of the referenced command buttons too. But it does not change back to its normal previous back color when I move to another command button. I also think it's better to formulate this code into a function , so that one can always call it on the mouse move event, instead of repeating it on each of them.

    Now the big issue is:

    1. The command buttons now flicker annoyingly a lot.

     How can I stop the controls or the screen from flickering with the application of this code.

    1. How can I get each command buttons back color change back to the previous color when I move to another one?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-06-30T09:36:54+00:00

    Hello,

    I really need it to always indicate the record  I want to enter its new record.

    Alittle clearification. the buttons to enter new records are labeled "enter New Records respectively.

    I am familiar with using the on mouse event to change the back color for a particular command button when I hover on it, but I normally use it on labels since command button already has that functionality with the use of theme.

    The command buttons already has their hover colors which shows when I hover on them but I don't know how to make the hover color for each command button show when I hover on another correspondent "enter new record" ones

    please do help,on how to do it.

    for the red color, I just used it as an example. I can use another mild color for the purpose.

    Thanks

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-06-28T21:54:55+00:00

    You'll also have to do something to change the color back when the user moves off that button, like the MouseMove event on the "section" your button lives in.

    I have to ask - why? That's quite a non-standard interface paradigm, and with good reason. Users would think they're doing something wrong if they hover over one button and another one changes colors (especially to Red, which means "STOP WHAT YOU'RE DOING").

    Was this answer helpful?

    0 comments No comments
  4. DBG 11,711 Reputation points Volunteer Moderator
    2016-06-28T21:22:46+00:00

    Hi. Just a guess but try using the MouseMove event. Hope it helps...

    Was this answer helpful?

    0 comments No comments