I want to handle the click on an CommandButton from within a class using the following class code
Option Explicit
Private m_First As MSForms.CommandButton
Private WithEvents evFirst As MSForms.CommandButton
Property Get First() As MSForms.CommandButton
Set First = m_First
End Property
Property Let First(ByRef o As MSForms.CommandButton)
Set m_First = o
Set evFirst = o
End Property
Private Sub evFirst_Click()
MsgBox "It Worked!"
End Sub
In addition to it not working, am wondering why the reference for the Button in the form is different from that in the class, ie:
Sub Tester()
Dim f As New UserForm1
Dim o As New cButtonClass
o.First = f.CommandButton1
Dim k1 As LongLong: k1 = ObjPtr(o.First)
Dim k2 As LongLong: k2 = ObjPtr(f.CommandButton1)
Debug.Assert k1 = k2 'NOPE!
End Sub
Why doesn't this work? What is the fix?