possible to sink a control event from a separate class?

possible to sink a control event from a separate class?

Post by rparde » Wed, 17 May 2006 00:50:31


Hey All,

I want to handle a combobox AfterUpdate event from a separate class
module. The below doesn't seem to work, *unless* I also create a
separate AfterUpdate handler right in the form module. I don't want to
have to do that. Is there something else I can do?

' -------------------------------------------
' Here is the entire class module:

Private WithEvents cmb As ComboBox

Property Set c(x As ComboBox)
Set cmb = x
End Property

Private Sub cmb_AfterUpdate()
MsgBox "In after-update!"
End Sub

' -------------------------------------------
' In the form I do this:

Private m As Class1

Private Sub Form_Load()
Set m = New Class1
Set m.c = Me.Combo0
End Sub
' -------------------------------------------

It feels like the form doesn't create the combobox 'withevents' unless
there's a handler right in the form module. Is that what's going on?
If so, is there a way around it?

Thanks!

-Roy
 
 
 

possible to sink a control event from a separate class?

Post by roy » Wed, 17 May 2006 05:34:57

For the record--this is possible. Here is a class that works:

' -------------------------------------------
' Here is the entire class module:

Private WithEvents cmb As ComboBox

Property Set c(x As ComboBox)
Set cmb = x
' This is the magic line of code:
cmb.AfterUpdate = "[Event Procedure]"
End Property

Private Sub cmb_AfterUpdate()
MsgBox "In after-update!"
End Sub

' -------------------------------------------

Cheers,

-Roy