WithEvents

R

Ronin

Group,

How is it that if i specify the below:

Public WithEvents mTestCtl As MSForms.TextBox

it will work fine, but if specified as MSForms.Control, it errors out with:

Run-time error '459':

Object or class does not support the set of events

please review the code below.

Public WithEvents mTestCtl As MSForms.Control
Sub SetControl(ctl As MSForms.Control)
Set mTestCtl = ctl '<-this is where it errors out
End Sub
Private Sub mTestCtl_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox mTestCtl.Value
End Sub


Please help.


Thanks in advance.


Ronin
 
D

Dnereb

withevents needs to know which events can be triggered.
and that's diffrent for a label opposed to a combobox.
 
C

Chip Pearson

A Control is a generic control. It can be set to any of the
controls in the MSForms library. Each of these controls has a
different set of events, and the compiler doesn't know what type
of control that variable will be set to, so it cannot generate
event code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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