Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form events - vbKeyTab doesn't register and neither do Mouse Clicks 1

Status
Not open for further replies.

SBendBuckeye

Programmer
Joined
May 22, 2002
Messages
2,166
Location
US
Hello All,

I have a class which is checking some things on the parent form using with events as shown in the skeleton below:
Code:
Private WithEvents mfrmParent As Form

Public Property ParentForm(Value As Form)
    Set mfrmParent = Value
    mfrmParent.KeyPreview = True
End Property

Private Sub mfrmParent_KeyUp(etc)
    If KeyCode = vbKeyReturn Then
        'Do Something
    End If
End Sub
The problems I have are as follow:

1. The KeyUp event does not trap the Tab key. If I put a breakpoint in the code, it is entered for all the rest of the keys but is never fired for the Tab key.

2. In the above code I use ActiveControl to determine which control has the focus. With the exception of the Tab key problem noted above, it is working well for keyboard entry. But, how do I handle mouse entry (eg user clicks in a listbox to select an item and then clicks on another control)? I thought there was a vbKey for the left mouse button but if there is, I missed it.

3. Can I use a generic mouse event in a similar manner to the KeyUp processing above? If so, is there some kind of correspondingpreview property I need to set to activate it? How do I determine which control has the focus in such a case?

Thanks in advance for any ideas, suggestions or best of all, a working code example to point me in the right direction!

Have a great day!

j2consulting@yahoo.com
 
You will get only form events. Clicking on a control does not raise a form event. vbKeyLButton and vbKeyRButton are constants you are looking for BUT I believe that they only have meaning in KeyDown and KeyUp which are triggered only for keyboard action.

Compare Code
 
Thanks John, even though its bad news it kind of confirms what I suspected. Any ideas on why the Tab key doesn't fire the KeyUp event? Thanks again!

Have a great day!

j2consulting@yahoo.com
 
Thanks, I know what it does, what I don't understand is why it doesn't fire a KeyUp event like all of the other keys.

Have a great day!

j2consulting@yahoo.com
 
Because it is considered a special key by the operating system, and gets 'eaten' before being passed on to the VB event handlers in order to do form navigation.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top