Change the On Mouse Wheel event

J

Jonathan Brown

Rather than have the form change records when I use the mouse wheel, I'd like
to have a listbox that's already been populated with values to just scroll up
or down. I can't imagine this should be too hard but I'm too much of a newb
to know how to do it. Many thanks.
 
B

Barry Gilbert

If the listbox already has the focus, the mouse wheel should scroll it. If it
doesn't you can trap the OnMouseWheel event and set the focus.

In the form's OnMouseWheel event, click the elipsis (...) to the right and
go to the Code Builder. Insert this code in the MouseWheel event:

Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
Me.MyListBox.SetFocus ' <---Insert this line of code
End Sub

Replace MyListBox with the actual name of your listbox. This will set the
focus to the listbox as soon as the form detects a wheel movement.

Barry
 
Top