possible to sink a control event from a separate class?

R

rpardee

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
 
R

roy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top