RefEdit in Class Module Problem

M

Mark Driscol

Excel 2002, Windows XP Version 2002, SP1

I have a RefEdit control on a UserForm that has both Change and Exit
events working without a problem. I subsequently defined a Class
module that would contain a RefEdit control and moved the UserForm's
code to the Class module. In the Class module, the Change event code
works without a problem, but the Exit event's code will not work. Even
something as simple as the code below won't work. Any ideas on why
not? One would think that if the Change event code worked, they Exit
event code would work as well.


Public WithEvents RefEdit As RefEdit.RefEdit

Private Sub RefEdit_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox "Hello"
End Sub


Thanks in advance.

Mark
 
M

Mark Driscol

Upon further researching this, it appears that the Exit event doesn't
exist in the Class module for a RefEdit control, although the Change
event does exist. Can anyone explain to me why the Exit event doesn't
exist? Without its existence, I suppose I am left to using the
original code in the UserForm?

Thanks.

Mark
 
M

Mark Driscol

Chip, I see you are online today, can you shed any light on this? Just
wondering if there is a way in advance to tell what Events are/are not
available in a Class module before formulating a solution.

Any input would be appreciated.

Mark
 
C

Chip Pearson

Some events are available only in the container object of the
control. This applies especially to text boxes, and a RefEdit is
just a juiced up text box. You can use the Exit event in your
form module:

Private Sub RefEdit1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox "exit "
End Sub

but the same will not work in a class module containing a
WithEvents RefEdit object.


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

Mark Driscol

Thank you, Chip, I discovered that after I had debugged the code in my
UserForm, and then ported it all over to my Class module. I just
didn't know if there were ways in advance to tell if an Event existed
in a Class module or not. I could have saved myself the trouble of
porting it over. I have several RefEdits on my UserForm and was trying
to avoid having to have separate Event codes for each one, but it
appears not.

Thanks for responding.

Mark
 
C

Chip Pearson

You can determine all the events supported by an object declared
WithEvents by selecting the variable name in the top left-hand
drop down in the code window. All events supported by that
control will appear in the right-hand drop down. If you select
an event from the right-hand drop down, VBA will insert the
proper Sub statement and an End Sub statement.


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

Mark Driscol

Thanks again, Chip.

Mark



Chip said:
You can determine all the events supported by an object declared
WithEvents by selecting the variable name in the top left-hand
drop down in the code window. All events supported by that
control will appear in the right-hand drop down. If you select
an event from the right-hand drop down, VBA will insert the
proper Sub statement and an End Sub statement.


--
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