我正在尝试创建一个类来管理 Access 2010 中组合框的事件。这里有代码:
类 TestEvents
Public WithEvents cbMyCombo As Access.ComboBox
Public Property Get AssociatedCombo() As Access.ComboBox
Set AssociatedCombo = cbMyCombo
End Property
Public Sub cbMyCombo_Change()
MsgBox "Combo has changed!"
End Sub
Private Sub Class_Initialize()
Set cbMyCombo = Form_Form1.Combo1
End Sub
Form1 代码(包含名为 Combo1 的组合框)
Option Compare Database
Option Explicit
Private MyTestEvents As TestEvents
Private Sub Form_Load()
Set MyTestEvents = New TestEvents
MsgBox MyTestEvents.AssociatedCombo.Name
End Sub
运行代码时,我(如预期)收到一条带有组合框名称 (Combo1) 的消息,因此 TestEvents.AssociatedCombo 属性指向正确的对象,但当我更改组合值时没有任何反应。我希望收到“组合已更改”的消息。
有什么我做错了吗?
在此先感谢您的帮助 :)