initialize userform, using a sub
Yes, a bit tricky, but doable.
Firsat, add a class module to your project and rename it clsUserformEvents.
Add this code to it
Option Explicit
Public WithEvents mCBGroup As msforms.ComboBox
Private Sub mCBGroup_Change()
MsgBox mCBGroup.Name & " has been changed"
End Sub
Then add this module variable to the top of your userform code
Private mcolEvents As Collection
and this line to your Userform_Initialize event at the end
CBGroup_Initilalize
and then add this procedure into your userform code module
Private Sub CBGroup_Initialize()
Dim cCBEvents As clsUserformEvents
Dim ctl As msforms.Control
Set mcolEvents = New Collection
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
Set cCBEvents = New clsUserformEvents
Set cCBEvents.mCBGroup = ctl
mcolEvents.Add cCBEvents
End If
Next
End Sub
--
HTH
RP
(remove nothere from the email address if mailing direct)
"natanz" wrote in message
oups.com...
another question:
on my userforms i have multiple comboboxes. whenever one of them is
changed i use the combobox*_change event to call a procedure. Is there
a way to generalize this event, so that anytime a combobox is changed
the procedure will be called, without having to have a separate
procedure for each combobox?
|