如何在Access2000窗体中检测并禁止通过鼠标滚轮滚动到其他记录-2

写不下了,接着上一篇,继续

6、打开 form_Customers 类,加入以下代码:

Option Compare Database
Option Explicit

'Declare a module level variable as the custom class
'and give us access to the class's events
Private WithEvents clsMouseWheel As CMouseWheel

Private Sub Form_Load()
'Create a new instance of the class,
'and set the class's Form property to
'the current form
Set clsMouseWheel = New CMouseWheel
Set clsMouseWheel.Form = Me

'Subclass the current form by calling
'the SubClassHookForm method in the class
clsMouseWheel.SubClassHookForm
End Sub

Private Sub Form_Close()
'Unhook the form by calling the
'SubClassUnhook form method in the
'class, and then destroy the object
'variable

clsMouseWheel.SubClassUnHookForm
Set clsMouseWheel.Form = Nothing
Set clsMouseWheel = Nothing
End Sub

Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)
'This is the event procedure where you can
'decide what to do when the user rolls the mouse.
'If setting Cancel = True, we disable the mouse wheel
'in this form.

MsgBox "You cannot use the mouse wheel to scroll through records."
Cancel = True
End Sub

7、保存,并关闭。

注意:
不要立即打开窗体验证代码是否正确,否则你的access将陷入长时间的停顿,因为 VBE 已经被加载了。
立即退出 Access ,然后重新打开数据库,滚动滚轮,你将看到以下提示:
You cannot use the mouse wheel to scroll through records.
并且记录没有更改。

以下是 ms 原文地址:http://support.microsoft.com/default.aspx?scid=kb;en-us;278379

下载地址如下:http://temp.shtip.com.cn/web/down/mousewheel.rar
文章原文如下:http://temp.shtip.com.cn/web/down/278379-mousewheel.mht

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus