I tried to use Keypress Event to disable the Tab Key. In Keypress Subroutine, I used "KeyAscii = 0" when vbKeyTab occurred. Text box still lost focus. I used same code to ignore Enter key and it worked as expected.
Advice anybody?
Thanx.
Printable View
I tried to use Keypress Event to disable the Tab Key. In Keypress Subroutine, I used "KeyAscii = 0" when vbKeyTab occurred. Text box still lost focus. I used same code to ignore Enter key and it worked as expected.
Advice anybody?
Thanx.
Try switching the forms "KeyPreview" property to true, and then typing some code in the KeyPress event of the form. Sorry, but I can't help you out with the code if you are after it.
Actually... The "KeyPreview" attribute tells the form to "CHECK" all keystrokes before allowing the relevant control to test for it.
What you want to do is test for the KeyDown even rather than KeyPress.
I think Tab is a value of 14 by memory but I could be wrong.
Sorry Gen-X, but Tab is a value of 9
Thanks KWell...
I knew it was in the sub 32 range somewhere.
The following did not work.I had similar code in KeyPress event subroutine. Neither recognized the Tab Key. Either the vbKeyTab constant is incorrect (I doubt that) or these subroutines do not provide for trapping & ignoring the Tab Key. Both allow for trapping & ignoring the Return Key.Code:Private Sub TxtMessage_KeyDown(KeyCode As Integer, _
Shift As Integer)
If KeyCode = vbKeyTab Then
KeyCode = 0
Junk = MsgBox("Tab Key") 'Dim for Junk is elsewhere
End If
End Sub
I tried the above with KeyPreview True & False.
My application can live without trapping the Tab Key. When Text Box is active, no control with a TabStop is visible, so focus is lost. I can Mouse click to return to Text Box, but it makes the application behave in a "Non-Professional" manner.
Any thoughts?
I couldn't figure it out either, but you could put another textbox under the one you are working with(by under I mean same top,left,height and width)and set it active and inactive with the one you are working with, then insert some code like this.
Private Sub txtHidden_GotFocus()
txtYouWantToIgnoreTabKey.SetFocus
End Sub
Not pretty, but it works.(I tried it)
Make sure hidden textbox is next in taborder.