Results 1 to 4 of 4

Thread: Trapping the tab key...

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    West Hartford, CT, USA
    Posts
    42
    I'd like to be able to detect if the tab key is pressed and perform my own event instead of going to the next object in the tab index.

    I've tried using the keypress event -- I don't see an "ascii 9" or a "vbKeyTab"

    The KeyUp and KeyDown events say specifically that they're not triggered for a tab event...

    Any ideas?

    Thanks

  2. #2
    Junior Member
    Join Date
    Feb 2000
    Posts
    18

    vbTab


    vbTab Chr(9) Horizontal tab.

    Hope this helps..

    Hemang

  3. #3
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374
    Andrew (good name my man), there is a vbKeyTab constant. I checked it to be sure in the keypress event of a textbox and it worked, like this:

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    
    If KeyAscii = vbKeyTab Then
        MsgBox "THIS IS A TAB!"
    
    Else
        MsgBox "THIS IS NOT A TAB!"
    
    End If
    
    End Sub
    Whatever control you are using should recognize the vbKeyTab constant. For the second part of your question, do this:

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    
    If KeyAscii = vbKeyTab Then
        KeyAscii = 0
        Text1.SetFocus
        'enter your subroutine or process here    
    
    End If
    
    End Sub

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Unfortunately here is how the Tab key works. If there is only one control on a form with TabStop = True, the Tab key will be recognized, but if there is more than one it won't be. What you need to do is in the form's Load event, store the TabStop values for all the controls that you are interested in, and then in the GotFocus even of each control set the TabStop property of all other controls to False, and then set them back to their originally stored vales in the LostFocus event.

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