Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Problems with event handlers

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?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Problems with event handlers

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


"Italian Job" wrote in message
...
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?





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Problems with event handlers

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?

"Chip Pearson" wrote in message
...
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


"Italian Job" wrote in message
...
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?







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
aauugghhh...#div/o problems & various average formula problems acbel40 Excel Worksheet Functions 5 October 19th 09 05:00 PM
MenuBar & Event problems Graham F Excel Discussion (Misc queries) 1 May 7th 06 10:26 AM
change event/after update event?? scrabtree23[_2_] Excel Programming 1 October 20th 03 07:09 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM
If... Then Loop problems in Worksheet Event TB[_3_] Excel Programming 2 August 4th 03 08:45 AM


All times are GMT +1. The time now is 04:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"