api - tracking LostFocus or Exit event of a combobox

G

Guest

Hi,

1. I am trying to capture the Exit or LostFocus event of a combobox on a
UserForm.
The Forms controls don't have a handle in vba and, while trying to find the
window 's class using Spy+, it seems like the combobox doesn't have a window
assicioted with it (unlike the listbox or a frame).
Any idea? Am i missing something?

2. If not direct way to (1)
To bypass the 'lack' of window for the combobox, i have placed the combobox
into a frame wrapped around it. However, i don't know how to get the handle
of the Frame. In spy++, the inside of the userform, the listbox, or the frame
have the same class (F3 Server 07600000).
Since I always show the frame programmatically (hidden most of the time) and
set its focus, I suppose i could use some sort of HitTest to determine the
window handle of the Frame. Then I could track the WM_KillFocus message
Any idea on a better approach?

Thank you for your help,

Sébastien
<http://www.ondemandanalysis.com>
 
J

Jim Cone

A ComboBox on a UserForm has both an Enter and Exit event.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"sebastienm"
<[email protected]>
wrote in message
Hi,
1. I am trying to capture the Exit or LostFocus event of a combobox on a
UserForm.
The Forms controls don't have a handle in vba and, while trying to find the
window 's class using Spy+, it seems like the combobox doesn't have a window
assicioted with it (unlike the listbox or a frame).
Any idea? Am i missing something?

2. If not direct way to (1)
To bypass the 'lack' of window for the combobox, i have placed the combobox
into a frame wrapped around it. However, i don't know how to get the handle
of the Frame. In spy++, the inside of the userform, the listbox, or the frame
have the same class (F3 Server 07600000).
Since I always show the frame programmatically (hidden most of the time) and
set its focus, I suppose i could use some sort of HitTest to determine the
window handle of the Frame. Then I could track the WM_KillFocus message
Any idea on a better approach?
Thank you for your help,
Sébastien
<http://www.ondemandanalysis.com>
 
G

Guest

I should have explained better, sorry.
I don't have access to the Combobox directly from the Userform; instead I
access it through a variable of a Class. When used through a variable in a
class, the combobox variable doesn't ?inherit? the Exit and Enter events
(while it supports _Change...), because (i believe) it comes from the generic
Control object.

Class1
--------
Private WithEvents mCombobox as msforms.combobox

Public Property Let Combobox(pCombobox as msforms.combobox)
set mCombobox=pCombobox
End Property

In a class module, while you can use some events like mCombobox_Change
event, some others cannot be used, like mCombobox_Exit. I think it's because
i comes from the COntrol object in fact.

I tried the following:
Class1
--------
Private WithEvents mCombobox as msforms.combobox
Private WithEvents mCtl as msforms.control

Public Property Let Combobox(pCombobox as msforms.combobox)
set mCombobox=pCombobox
set mctl = pCombobox
End Property

but then it breaks at run-time on
Set mCtl = pCombobox
with err 459 - Object or Class does not support the set of events.

Any idea?
 
G

Guest

I should have explained better, sorry.
I don't have access to the Combobox directly from the Userform; instead I
access it through a variable of a Class. When used through a variable in a
class, the combobox variable doesn't ?inherit? the Exit and Enter events
(while it supports _Change...), because (i believe) it comes from the generic
Control object.

Class1
--------
Private WithEvents mCombobox as msforms.combobox

Public Property Let Combobox(pCombobox as msforms.combobox)
set mCombobox=pCombobox
End Property

In a class module, while you can use some events like mCombobox_Change
event, some others cannot be used, like mCombobox_Exit. I think it's because
i comes from the COntrol object in fact.

I tried the following:
Class1
--------
Private WithEvents mCombobox as msforms.combobox
Private WithEvents mCtl as msforms.control

Public Property Let Combobox(pCombobox as msforms.combobox)
set mCombobox=pCombobox
set mctl = pCombobox
End Property

but then it breaks at run-time on
Set mCtl = pCombobox
with err 459 - "Object or Class does not support the set of events."

Any idea?
 
J

Jim Cone

Sébastien,
Sorry no ideas at this time.
Jim Cone



"sebastienm"
wrote in message
I don't have access to the Combobox directly from the Userform; instead I
access it through a variable of a Class. When used through a variable in a
class, the combobox variable doesn't ?inherit? the Exit and Enter events
(while it supports _Change...), because (i believe) it comes from the generic
Control object.

Class1
--------
Private WithEvents mCombobox as msforms.combobox

Public Property Let Combobox(pCombobox as msforms.combobox)
set mCombobox=pCombobox
End Property

In a class module, while you can use some events like mCombobox_Change
event, some others cannot be used, like mCombobox_Exit. I think it's because
i comes from the COntrol object in fact.

I tried the following:
Class1
--------
Private WithEvents mCombobox as msforms.combobox
Private WithEvents mCtl as msforms.control

Public Property Let Combobox(pCombobox as msforms.combobox)
set mCombobox=pCombobox
set mctl = pCombobox
End Property

but then it breaks at run-time on
Set mCtl = pCombobox
with err 459 - "Object or Class does not support the set of events."
Any idea?
 

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