I'm trying to create a class that manages the events of a combo box in Access 2010. Here you have the code:
Class 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 Code (Contains a combobox named Combo1)
Option Compare Database
Option Explicit
Private MyTestEvents As TestEvents
Private Sub Form_Load()
Set MyTestEvents = New TestEvents
MsgBox MyTestEvents.AssociatedCombo.Name
End Sub
When running the code, I get (as expected) a message with the combobox name (Combo1), so the TestEvents.AssociatedCombo property is pointing to the right object but nothing happens when I change the combo value. I would expect to get the message "Combo has changed".
Is there anything I'm doing wrong?
Thanks in advance for your help :)