Problems with event handlers

I

Italian Job

Is it possible for me to test if a control does or doesnt have focus?

Some event handlers are called even when the associated event wasn't user
generated. For example, if a listbox.list is updated in another method, the
listbox_click handler is called.


Sub listbox_click()

some code

End sub


Can I test to see if the user clicked the control or if another method
called it, by
testing for focus? For example:



Sub listbox_click()

if gotfocus(listbox) then some code

End sub

The code inside the event handler is executing when I don't want it to. Is
there a way to stop this?
 
C

Chip Pearson

The ActiveControl property of the form will return a reference to the
control with focus. For example,

MsgBox UserForm1.ActiveControl.Name


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

Italian Job

Yes. Thank you Chip. It works perfectly with single layer forms.

What about when I have a multipage form. It doesnt seem to work then. It
keeps returning "Frame 1". Is this a limitation?
 

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