Event Sinking

nathansav

Registered User.
Local time
Today, 12:57
Joined
Jul 28, 2010
Messages
114
Hi,

I am trying to sink the events of 42 command buttons on one form. I have created the class clsCustomCommandButton

Code:
Option Compare Database
Private WithEvents mCommandButton As CommandButton
Public Property Set CommandButon(ByVal oCommandButton As CommandButton)
    Set mCommandButton = oCommandButton
End Property
Private Sub mCommandButton_Click()
    MsgBox "Working"
End Sub

and have the following code in my form

Code:
Option Compare Database
Private EVENT_HANDLERS As Collection
Private Sub Form_Load()
    Set EVENT_HANDLERS = New Collection
    Dim oControl As Control
    For Each oControl In Me.Controls
        If oControl.ControlType = acCommandButton Then
            Dim oEventHandler As CustomCommandButton
            Set oEventHandler = New CustomCommandButton
            Set oEventHandler.CommandButon = oControl
            EVENT_HANDLERS.Add oEventHandler
        End If
    Next oControl
    
End Sub

But it doesnt work, can anyone assist?

Thanks
 
In order for a control to raise events, you need to set its OnEventname property to "[Event Procedure]"
Code:
cmdButton0.OnClick = "[Event Procedure]"
 

Users who are viewing this thread

Back
Top Bottom