disable tab keystroke in text field in form

Posted on 2009-04-29
Last Modified: 2013-11-26
How can i trap for a tab key pressed and disable the action.  Or turn the tab key into a return key to call a function i have in the return key

The whole idea is to change the value of an input field when the user leaves that field.  I have a function that works on with the return key but not with the tab key.

Question by:norway77
    LVL 15

    Expert Comment

    LVL 48

    Accepted Solution

    You can do something like this:
        Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean
            If Me.TextBox1.Focused Then
                Return True
                Return MyBase.ProcessTabKey(forward)
            End If
        End Function

    Open in new window


    Author Comment

    Ok, better definition:

    I want to go thru a form with multiple textboxs and edit the fields as I go. Using the txtbox1.keydown and txtbox1.keypress I seem to be able yo captue the [Enter] key, validate the data and either move to the next txtbox2 if good or display an error message and re-focus on the current txtbox1.  The problem is these methods do not seem to trap the [Tab] key - which then bypasses my edits.  Using the following code I am able to capture the tab key, validate the data but I cannot suppress the key and re focus on the current txtbox...

            Protected Overrides Function ProcessCmdKey(ByRef msg As Message, _
                               ByVal keyData As Keys) As Boolean
            Const WM_KEYDOWN As Integer = &H100
            Const WM_SYSKEYDOWN As Integer = &H104

            If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
                Select Case (keyData)

                    Case Keys.Tab
                        'MsgBox("Tab Key Captured in the " + Me.ActiveControl.Name + " control!")

                        'I can do something based on the active control
                        Select Case Me.ActiveControl.Name
                              case TxtBox1
                                   if not  validatedata1() then
                                       DON'T PROCESS TAB KEY!!!  ?????
                                   end if
                        end select

    Any way to not tab here?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now