Results 1 to 6 of 6

Thread: VB - A demonstration of how to trap the Tab key

  1. #1

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Scottsdale, Arizona, USA
    Just to note one thing. Before assigning the TabStop property to False, first check if the control is not Label, Image or Line. These controls don't have TabStop property because they are being painted directly on the form.

  3. #3

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    San Jose, CA
    Thanks Serge. The StoreTabsStops sub in the form has the following statement:

    VB Code:
    1. 'Store the TabStop property for each control on the form. If you run into
    2.     'a control without a TabStop, just add an On Error Resume line
    I probably should have just included the On error Resume Next line instead of the advice.

  4. #4
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Back to VBF.
    Here is another way ..
    Put two textboxes on the form ..

    VB Code:
    1. Option Explicit
    3. Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    4. Private Const VK_TAB = &H9
    6. Private Sub Text2_LostFocus()
    7.     If GetTabState Then MsgBox "You just tabbed out of Text2"
    8. End Sub
    10. Private Sub Text1_LostFocus()
    11.     If GetTabState Then MsgBox "You just tabbed out of Text1"
    12. End Sub
    14. Private Function GetTabState() As Boolean
    15.     GetTabState = False
    16.     If GetKeyState(VK_TAB) And -256 Then
    17.         GetTabState = True
    18.     End If
    19. End Function

    Simple, Effective and Efficient code ...

  5. #5

  6. #6
    Addicted Member
    Join Date
    Feb 2004

    Re: VB - A demonstration of how to trap the Tab key

    Quote Originally Posted by techyspecy View Post
    Here is another way ..

    Simple, Effective and Efficient code ...
    EXCELLENT solution! Many thanks.
    Last edited by Jimboat; Jul 4th, 2019 at 05:31 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width