Im working on a VBA program where on the form I create some textboxes and buttons dynamically.
I want to handle events for the dynamically created objects.
I think Addhandler is the way to do this but I can't seem to figure out exactly how it works, even after extensive googling. Any help would be much appreciated.
Here is a test setup of my code:
On the form:
Public i As Integer
Private Sub Form_Load()
Private Sub CommandButton1_Click()
Set cmbobject = UserForm1.Controls.Add("forms.commandbutton.1")
.Name = "textbox" & i
.Caption = "text" & i
.Width = 50
.Left = 10
.Top = 10 + (i * 20)
.Height = 20
AddHandler cmbobject.Click, AddressOf cmbobject_Click
i = i + 1
and in a separate module in the same project:
Public Sub cmdobject_click()
The AddressOf keeps giving me the error message : expected sub, function or property
and if I change it to:
AddHandler cmbobject.Click, AddressOf Module1.cmdobject_click
it says: sub or function not defined
Thanks in advance