Link to home
Start Free TrialLog in
Avatar of Tomas_Jirsak
Tomas_Jirsak

asked on

Tab key

Hi,

I am a beginner in VB and am working on a VB key trapping using the KeyPress procedure. I'd like to make a condition statement for pressing the Tabelator key (I tried both vbKeyTab and its ASCII code 9) in the text box control during runtime. But this condition is ignored and cursor moves to the next control in the order of TabIndex. Is there a way how to make the program respond to pressing the Tab key (without setting the TabStop property to False)?

Thank you in advance,
Tomas Jirsak
jirsak@bnl.gov

P.S1. I tried without success also KeyDown and KeyUp procedures.
P.S2. A very simple example is below.


--------------------------------

Private Sub txtPosition4_KeyPress(KeyAscii As Integer)
Select Case True
    Case KeyAscii = vbKeyTab
        MsgBox "That was a Tab key"
    Case Else
        MsgBox "That WAS NOT a Tab key"
End Select
End Sub

---------------------------------
Avatar of Juilette
Juilette

You can set the Tabstop property to false for all the controls:

Private Sub Form_Load()
Dim i As Integer
On Error Resume Next
For i = 0 To Controls.Count - 1   ' Use the Controls collection
    Controls(i).TabStop = False
Next
End Sub
Oooops...sorry...didn't clue in on the not set to false.
Wayne
Avatar of Tomas_Jirsak

ASKER

Juliette's answer is exactly what I don't want,  i.e. setting properties of all the controls to False (this is explicitly mentioned in my question).
ASKER CERTIFIED SOLUTION
Avatar of credo
credo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Neither the KeyPress nor the KeyCode events respond to the tab key as stated in the original question.  I have noticed this in VB6 AND VB3.  Does anyone have a real solution?