Thank you,
This is what I needed. I really appreciate this clear answer.
"Stephen Bullen" wrote:
Hi AWesner,
How do I raise a click event for an object created at runtime?
I would do option #3 - use a class module to handle the events:
Class CListEvents
Public WithEvents mlbList As MSForms.ListBox
Private Sub mlbList_Click()
' your code
End Sub
Then when creating your form, create a new instance of this class for
each list box:
'At the top of the module
Dim mEventClasses As Collection
'At the top of your 'create the tabs' routine
Dim clsListEvents As CListEvents
Set mEventClasses = New Collection
'When creating each list, hook its events
'Creates a listbox to input filter codes into
Set ctrTList(X) = frmConfig.mpgType.Pages(X -
1).Controls.Add("Forms.ListBox.1")
Set clsListEvents = New CListEvents
Set clsListEvents.mlbList = ctrTList(X)
mEventClasses.Add clsListEvents
There are lots of reasons why this way is better than trying to add
code programmatically.
Regards
Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk