Works fine with one control, but thats not what i want.
Is there any other way out where there are more controls.
Printable View
Works fine with one control, but thats not what i want.
Is there any other way out where there are more controls.
hmmm... you know theres a post with the same question 1 post below yours huh?!
so why don't wait for anyone to answer there?
hmmkay :)
http://209.207.250.147/showthread.ph...467#post172467
In case you're lazy:
Here's a modified one for ya, in case you're extremely lazy :) (without comments ok? :))Code:'Set all the tabstop of all controls to false
Private Declare Function GetFocus Lib "user32" () As Long
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim h&
If KeyAscii = vbKeyTab Then 'vbKeyTab = ASCII char 9, but constants look better imho (in my humble opinion )
h = GetFocus 'gets the handle of the control in focus.
If h = Text1.hWnd Then MsgBox "TAB AT TEXT1" 'reminds you that text1 has focus.
Text2.SetFocus 'then move on to the next control, just as normal.
End If
End Sub
Private Sub Form_Load()
KeyPreview = True 'receive all keystrokes before the controls do (sort of subclassing, but then easy )
End Sub
Code:'This example uses 2 textboxes, both with tabstop to false.
Private Declare Function GetFocus Lib "user32" () As Long
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim h&
If KeyAscii = vbKeyTab Then
h = GetFocus
If h = Text1.hWnd Then
MsgBox "TAB AT TEXT1"
Text2.SetFocus
ElseIf h = Text2.hWnd Then
MsgBox "TAB AT TEXT2"
Text1.SetFocus
End If
End If
End Sub
Private Sub Form_Load()
KeyPreview = True
End Sub
:p
Jop --
Maybe I'm really missing something, but I still can't get Form_Keypress to fire when hitting a tab. I tried your code but it's not working.
Any suggestions?
Elizabeth
Did you set all the control's tabstop to false?
Jop --
Bear with me, I'm just a beginner.
The form has at least 100 controls. I worry that if I take out the tab stops, won't I have to hard-code the tab order if I use the method you suggest? Or am I missing something?
Let me try just a bit to describe my situation a bit more.
I have a form with four frames in it (well, there are more, but four major ones). These have tabs associated with them, so the user can click on the tabs to access the four frames.
It's used for data entry, and also used for updating old entries.
I'd like the user to be able to tab through the first frame, and when on the last textbox, to be able to hit tab and be automatically sent to the next frame.
I thought I could do this by detecting a tab in the last textbox, and trigger appropriate code to send the user to the next frame. (and, also, if the user hits shift-tab in the first textbox, to send him back a frame).
I've tried keypress, keydown, and keyup, and can't get any of them to detect tab.
I'm working on a solution with invisible command buttons which, when they get the focus, automatically kick the user to the next frame. But a few problems starting cropping up with this approach; I'll be working on it more on Monday to see if I can make this approach work.
But if there's some way I can detect tab when the user is on the last textbox on the frame, well, that would be ideal.