Discussion Locked

Preventing Mouse Wheel Event

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How can I programmatically prevent the mouse wheel event?

Even when a form is set to "Current Record Only", the mouse wheel enables a user to scroll through ALL my records.

Office XP has a "Mouse Wheel" Event Procedure, but how do I use it? Any examples?

Thanks much!

6 replies

by sl-campbell

MS says:

"The MouseWheel event is interesting in theory, but in practice it suffers from implementation. Here's the declaration for the event:

Private Sub Form_MouseWheel( _
ByVal Page As Boolean, ByVal Count As Long)

Notice what's missing? There's no Cancel argument. You can sense that the user is changing records on a form via the mouse wheel, but you can't do anything about it. In addition, given that you're going to receive a Current event as well, it's hard to come up with a good use for the MouseWheel event"

About the only way to prevent this is to restict the records returned by using a (Parameter) query with criteria for the forms' underlying recordset so the records returned are only that one record. Use the query editor for this.

You could also programically disable the mouse wheel via API calls.

by seagull data services

The example below is based on the categories table of the Northwind.mdb from Access 2000
It should be relatively simple to adapt it to your database.
What it does is return a single record from the Categories table.
You will need to unbind your table from the form and set the Allow Additions property (if it's the same in XP) to No. This will prevent access scrolling to a blank record
The form has cmdNext and cmdPrev command buttons to allow movement to the next/previous record.
When the form loads the Form_Load procedure displays the first record in the table by setting the recordsource property of the form.

When the cmdNext button is clicked the recordsource property is altered to show the next record in the recordset. If no records are returned (no more records in table) the last record is shown.

The cmdPrev button works similarly.

I'll post the code as a comment.
Hope this helps
John

by seagull data services

The Code:

Option Compare Database
Option Explicit

Public Sub ShowFirst()
Me.RecordSource = "SELECT TOP 1 C.CategoryID, C.CategoryName, C.CategoryName, " & _
"C.Description FROM Categories C;"
End Sub

Public Sub ShowLast()
Me.RecordSource = "SELECT TOP 1 C.CategoryID, C.CategoryName, C.CategoryName, " & _
"C.Description FROM Categories C order by C.CategoryID Desc;"
End Sub

Private Sub Form_Load()
ShowFirst
End Sub

Private Sub cmdNext_Click()
Me.RecordSource = "SELECT TOP 1 C.CategoryID, C.CategoryName, C.CategoryName, " & _
"C.Description FROM Categories c where C.CategoryID > " & Me!CategoryID & ";"
If Me.RecordsetClone.RecordCount = 0 Then
Beep
ShowLast
End If
End Sub

Private Sub cmdPrev_Click()
Me.RecordSource = "SELECT TOP 1 C.CategoryID, C.CategoryName, C.CategoryName, " & _
"C.Description FROM Categories c where C.CategoryID < " & Me!CategoryID & _
" Order by C.CategoryID Desc;"
If Me.RecordsetClone.RecordCount = 0 Then
Beep
ShowFirst
EndIf
End Sub

This discussion is closed to new replies.