Results 1 to 7 of 7

Thread: Preventing Tab

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I have a text box that I don't want people to be able to tab out of. In the KeyPress event, I already tried this code:

    If KeyAscii = vbKeyTab Then KeyAscii = 0

    But it didn't work. It still tabs out of the textbox. I also tried:

    If KeyAscii = vbKeyTab Then
    KeyAscii = 0
    Cancel = 1
    End If


    And

    If KeyAscii = vbKeyTab Then
    KeyAscii = 0
    txtedit.SetFocus
    End If


    But that didn't work either. Any suggestions on how to keep it from tabbing out of the textbox?

    ------------------
    Ryan

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Posts
    76

    Post

    Try it in the keydown event or Keyup event

  3. #3

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    No, that didn't work. I think it's because in the KeyDown and KeyUp events the KeyAscii doesn't work.

    ------------------
    Ryan

  4. #4
    Junior Member
    Join Date
    Aug 1999
    Location
    Behinf you
    Posts
    24

    Post

    First of all, in the KeyDown and KeyUp command you have Keycode insted of the KeyAscii.
    Second, It still won't do what you want it to do... I really don't remember the way to do what you want but you can try setting all the "Tabstop" values to false...
    If you don't get a better reply I'll try finding the easier way to do it

  5. #5

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I can't set all the TabStop values to 0 because I still need to be able to tab to the other textboxes, but just not from this textbox.

    ------------------
    Ryan

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    What The_Inspector suggested is really your only solution, here's an example of how to implement it easily without loosing all Tab Functionality:
    Code:
    Private Sub Text1_GotFocus()
        EnableTabs False
    End Sub
    
    Private Sub Text1_LostFocus()
        EnableTabs
    End Sub
    
    Private Sub EnableTabs(Optional ByVal EnabledThem As Boolean = True)
        On Error Resume Next
        Dim oControl As Control
        For Each oControl In Controls
            oControl.TabStop = EnabledThem
        Next
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

  7. #7

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    ok, yeah, now I see how I can apply what The_Inspector said. Thanks for your help, both of you.

    ------------------
    Ryan

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