Hi all,
I am trying trying to make both the "Tab Key" behave as the "Enter" key. keys. In otherwords, both the Tab and Enter should acheive the same objective.

I am using the code below but only the "Enter" key is working, but the "Tab" key is not working.

How can I get this accomplished?

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Or KeyAscii = 13 Then cmdGo_Click
End Sub

Thanks.
tgifgemini

Recommended Answers

All 9 Replies

it cause TAB key used by VB 6 to move focus from one control to other control. it can't be changed. see tab index on the properties of controls, it used if user press the tab key only. if u want to change the tab function, so how to move tab index purely from vb (without use set focus on other key). but its can't be changed. :)
ok. its from me.
all for the best.

Private Sub Text1_LostFocus()
cmdGo_Click
End Sub

If you want to trap the Tab key in the KeyPress event, you have to disable to TabStop property in all other controls on the form, but you will have to handle moving the control focus yourself. Once the TabStop property is set to false, the Tab key will be trapped in the KeyPress event. Be sure to set the KeyPreview property on the form.

On Error Resume Next
For Each Control In Controls
Control.TabStop = False
Next

when you press the tab key it will jump to the next higher index from its focused control. for example. you have 3 controls and they are text1, text2, command1. if you put first the text1 in the form the tabindex of that control is zero, right? then you put again another control and this time its command1, therefor the tabindex of command1 is 1, then the text2, of course the tabindex of text2 is 2.

so...

if you run the program and presses the tab key, the focus will move according to their tabindex, ergo if the focus is on the text1 and you press the tabkey the focus jumps to ??? yeah to comand1, then to text2.

your problem is you want the focus to be synchronized and must behave like this. from text1 to text2 then to command 1, right?

what I did on this is just simply delete the first control then undo, then delete the next one then undo...delete, undo, delete undo... did you get my point? hahahahaha that's the faster way I used to that problem.... enjoy deleting hehehehehe dont forget to undo the deletion...

Opppps I forget the enter key...

In each control put this code in the Keypress event

If KeyAscii=13 Then
sendkeys "{tab}"
End If

Opppps I forget the enter key...

In each control put this code in the Keypress event

If KeyAscii=13 Then
sendkeys "{tab}"
End If

can someone teach me..i have grid.. the grid have 3 columns and 12 rows and i want use tab as the control to jump to each columns and rows..can somebody give me ade key code for the tab??how to know the keycode for tab??
really appreciate ur helps.
TQ.

commented: By now, you should know to make a new thread. -2

1. Open Visual Basic
2. Press F2
3. search for "KeyCodeConstants"

TQ. it's really help me.

but how can set focus for controls when they are 20.any function has to create for all?

commented: this thread is 3 years old. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.