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!

Hot Keys 3

Status
Not open for further replies.

vsprogrammer

Programmer
Joined
Jun 26, 2006
Messages
40
Location
CA
Hi! I am new to this, please forgive if it does not make sense. I have a vb6 form with hotkeys on labels to bring me to the textbox when hit, ie.) on the caption I have "&Invoice #:" but when you hit Alt+I it does not work - nothing happens. So I tried to do the following on the form - keydown():
Code:
If vbAltMask Then    
    Select Case KeyCode
        Case vbKeyI
            txtInvoiceNbr.SetFocus
            KeyCode = 0
    End Select
   End If
End If
PLEASE HELP.... Thanks!
 
You shouldn't have to use the keydown event. If you do use it, then you should make sure that the form's KeyPreview property is set to TRUE.

I think the pressing the hotkeys for a label will cause the focus to go to the next control in the tab list. Do this...

1. Open the form so that you can see the controls.
2. Click on the label control.
3. In the properties window, scroll down to the TabIndex property. take note of the number.
4. Click on the text box that you want to get the focus (as a result of the hot key).
5. Make sure that the tabindex is set 1 higher.

Ex. If TabIndex for the label is 12, then set the TabIndex for the text box to 13.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi George,
Thanks for the reply, I checked the keypreview and it is set to TRUE. However, it is still not working, I set the tabindex to the next # after my label tabindex. It seems to be crapping out at the when the alt key is pressed and not even going into the select case to check if the vbkeyI is being hit. Is there somewhere else on the form that I can put this code?
Thanks!
 
I think you misuderstood me.

My suggestion was to NOT use the key down event.

Remove the code, set the keypreview to false, and check the tab indexes.



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
They way you are checking for the ALT key isn't right either. Here's how I usually do it...

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    
    Dim bShiftKey As Boolean
    Dim bAltKey As Boolean
    Dim bCtrlKey As Boolean
    
    bShiftKey = Shift And vbShiftMask
    bAltKey = Shift And vbAltMask
    bCtrlKey = Shift And vbCtrlMask
    
    Debug.Print bShiftKey, bAltKey, bCtrlKey

End Sub

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
If you set the tabindex value of your text box to the next number after your label, then it should work, no matter what the events are doing. In fact, this behavior happens before any of the keyup or keydown events are executed.

Try making a small form with one or two label textbox pairs and see if you can get that to work as intended. Other than that, I have to believe that you're getting your tabindexes confused.

HTH

Bob
 
I have finally gotten around to fixing this, you were both correct in what you were saying, it was the sequence of the tab indexes that was causing the trouble. When I first looked at it my tab sequence on my label was set at 38 and my textbox was at one. So I changed my label to be one and my textbox to be two and continued on with the sequence, whom ever created the form only put tabbing on the textboxes. Thanks for all your help! Greatly appreciated!
 
< whom ever created the form only put tabbing on the textboxes

That's a very common error, since it's counterintuitive to have a tabindex property on a non-focusable control such as a label.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top