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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TAB KEY

Status
Not open for further replies.

scasystems

Programmer
Jan 15, 2003
44
0
0
GB
When a user presses ENTER in a text box, I want it to respond as though the user pressed TAB. How is this possible?
 
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
Case 13
SendKeys "{Tab}"
End Select

End Sub
 
I have seen some awkward things when using SendKeys. Another alternative trick is simply to set the .Enabled property of the control (your text box) to False, then reset it to True. This approach seems to provide a smoother solution as far as what is displayed on the screen. BlackburnKL
 
awkward things when using SendKeys? can i please know what all? Thanks,
Ebee Sam
 
We were using a KeyPress event to capture the Enter key and send the Tab key. This allowed data entry operators (fast typists) to use the older style (and more intuitive) navigation approach while performing "heads down" data entry.

The problem that we encountered was that the NumLock was temporarily shut off using SendKeys, then turned back on.

Since "heads down" data entry does not require the operator to watch the screen much, this resulted in keystrokes being "lost" while the NumLock was disabled. We switched to the .Enabled property approach I described (which I found in this forum after much searching) and the problem has disappeared. BlackburnKL
 
I thing you can use SetFocus event instead of SendKeys which is, like BlackburnKL said, sometimes not that easy to use. Let's say you have 2 Tab controls on the form. In that case using SendKeys statement will become a little bit more complicated.

Code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
 Select Case KeyCode
    Case 13
         TabStrip1.SetFocus
    End Select
End Sub
 
Kel1981b - There is a fundamental difference between using the explicit SetFocus option described in your immediately preceeding post, and the SendKeys method described by ebeesam above.

In your method, focus will always move from the TextBox to the TabStrip1 (or whichever control has specified in the code), whereas the SendKeys will move to the focus to the next control in the current tab order.

There are times where either may be correct and/or preferable, but important that the developers be aware of the difference between the two. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
CajunCenturion. There is no question about the diference between thowse two. Moreover, I know what the diference is. For me, using SetFocus, in case like that, just is easier and more comfortable because I do not have to be care about tab order. This is it. It's just my style of programming: use less complicated and easier way. I choose this way 10 years ago ...
 
The method I mentioned in my earlier post also moves to the next control in the tab order (accomplishing the same thing as sending a tab with SendKeys). It just avoids a problem we encountered.

I have also used the direct SetFocus approach at times in the past, but I am shying away from it more and more (except in circumstances where I specifically need to use it). Depending on where you place a SetFocus command in your form's events, you can get some really interesting things to happen. I've encountered situations where the code executed when running without stops is different than the code executed when you are tracing it through step by step.

As with most things, there are pros and cons to just about any approach to anything. However, there are certainly smarter choices and dumber choices under specific sets of circumstances. Sharing our experiences in a forum such as this helps us all (I hope) to make the smarter choices more often than we might strictly on our own. BlackburnKL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top