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-15T03:46:09+00:00

    without space on detail section, i think you need to run the codes behind each button on mouse move instead of behind mouse move on detail.

    o, so much codes.

    Was this answer helpful?

    0 comments No comments