Try this code. I use it in a form and works fine.
SET UP NEW MODULE AND COPY THIS CODE IN IT. THEN GO TO THE FORMS PROPERTY AND IN THE ONLOAD EVENT COPY THE CODE IN RED.
Private Sub Form_Load()
' Highlight command buttons as the mouse hovers over them
gSetupCmdHighlights Me
End Sub
'
''''''''''''''''''''''''''''''''''''''
' Original coding by Terry Bell '
' Bellco (Vic) Pty Ltd '
' 8 Dreadnought St '
' Sandringham Vic 3191 '
' Australia '
' 061 3 9598 4453 '
' Email: tbell at the following ISP '
' netspace.net.au '
''''''''''''''''''''''''''''''''''''''
Function gSetupCmdHighlights(frm As Form)
Dim cntl As Control, Sctn As Section, i As Integer
'Set the OnMouseMove event for all Command Buttons to function gMouseMove
'Set the OnMouseMove events for all non-Command button controls to function gClearCmdHighlights
For Each cntl In frm.Controls
Select Case cntl.ControlType
Case acCommandButton
cntl.OnMouseMove = "=gMouseMove(""" & frm.Name & """," & cntl.Name & ")"
Case 112 'Subform has different syntax (".Form.") shown below _
cntl.Form.OnMouseMove = "=gClearCmdHighlights(""" & frm.Name & """)"
Case Else
On Error Resume Next
cntl.OnMouseMove = "=gClearCmdHighlights(""" & frm.Name & """)"
On Error GoTo 0
End Select
Next
'If the mouse moves over a different report section, switch any highlight off
On Error Resume Next
For i = 0 To 4
frm.Section(i).OnMouseMove = "=gClearCmdHighlights(""" & _
frm.Name & """)"
Next
On Error GoTo 0
End Function
Function gMouseMove(frm, CtlName As Control)
'You only get here from OnMouseMove events that happen over command buttons
'If the command button is not already highlighted (in blue),
'the current fore color is saved in the tag property of the button
'and the colour is set to blue
'Then any other command buttons on the form are checked and if they
' are highlighted they are switched off.
'The second for each caters for the situation where you have two immediately adjacent command buttons with no 'intervening other form controls which would otherwise take care of switching off the highlighting
'on the command button being vacated.
'On the line marked *** you can experiment with different colours
Dim cntl As Control, fm As Form
Set fm = Forms(frm)
On Error Resume Next
If CtlName.ControlType = acCommandButton And CtlName.Tag = "" Then
CtlName.Tag = CtlName.ForeColor 'Save original forecolor
CtlName.ForeColor = vbBlue '***
End If
For Each cntl In fm.Controls
If cntl.ControlType = acCommandButton And _
CtlName.Name <> cntl.Name And cntl.Tag <> "" Then
cntl.ForeColor = cntl.Tag
cntl.Tag = ""
End If
Next
On Error GoTo 0
Set fm = Nothing
End Function
Function gClearCmdHighlights(frm)
'This clears the highlights on all command buttons in the form
'and restores the original forecolors that were saved in the Tag properties
Dim cntl As Control, fm As Form
Set fm = Forms(frm)
For Each cntl In fm.Controls
If cntl.ControlType = acCommandButton And cntl.Tag <> "" Then
cntl.ForeColor = cntl.Tag
cntl.Tag = ""
End If
Next
Set fm = Nothing
End Function
Good luck