How do i make a button highlight when you mouse or tab over it?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slenish
    Contributor
    • Feb 2010
    • 283

    How do i make a button highlight when you mouse or tab over it?

    Hello all,

    What I have is a button that I want to make either hightlight or dissapear and then reapper when you mouse over or tab over the button. I had it working but then I kept getting a bunch of errors so I wanted to get some help on the matter.

    What I did was is I took this code and put it in to a module;

    Code:
    Function HighlightControl(ControlName As String)
    
    With Me.Controls(ControlName)
    If .FontSize <> 13 Then
    .FontSize = 13
    .ForeColor = 49915
    End If
    End With
    
    End Function
    
    Function UnhighlightControls()
    
    Dim ctl As Access.Control
    
    For Each ctl In Me.Controls
    With ctl
    If .Tag = "Highlight" Then
    If .FontSize <> 12 Then
    .FontSize = 12
    .ForeColor = 16776960
    End If
    End If
    End With
    Next ctl
    
    End Function
    Then I took another command
    Code:
    =UnhighlightControl(CommandButton)
    and put it in to the Expression Builder, OnMouseMove property of the button.
    It started to work but then it just started to error out. Is there something Im missing or forgot to do?

    Thanks in advance for the help
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. Add both Functions to your Form's Code Module. I reformatted them and added Code Tags for clarity.
      Code:
      Private Function UnhighlightControls()
      Dim ctl As Access.Control
        
      For Each ctl In Me.Controls
        With ctl
          If .Tag = "Highlight" Then
            If .FontSize <> 12 Then
               .FontSize = 12
               .ForeColor = 16776960
            End If
          End If
        End With
      Next ctl
      End Function
      Code:
      Private Function HighlightControl(ControlName As String)
      With Me.Controls(ControlName)
        If .FontSize <> 13 Then
          .FontSize = 13
          .ForeColor = 49915
        End If
      End With
      End Function
    2. For each Control that you wish to be involved in this Highlight/Unhighlight process:
      1. Set their Tag Property to Highlight
      2. In the Row next to the On Mouse Move Event Property, enter the following line where <Control Name> is the actual Name of the Control:
        Code:
        =HighlightControl("<Control Name>")
    3. In the Row next to the On Mouse Move Event Property of the Form's Detail Section, enter the following line of Code:
      Code:
      =UnhighlightControls()
    4. You should be good to go at this point.

    Comment

    Working...