Disable Tab Off a Text Box

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Disable Tab Off a Text Box

Post by Leesha »

Hi,
I have a text box on form set to Long Text. It is set to no for tab stop. The user makes notes in it on clients. If they hit the enter key to go to the next line in the box they are fine. However if they hit tab by accident they go to the first field in the record. Their goal is to have nothing happen if they hit tab. Is there code for that and what event would it be put on. I've tried various things but nothing has worked.
Thanks,
Leesha

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Disable Tab Off a Text Box

Post by HansV »

Create an On Key Down event procedure for the text box:

Code: Select all

Private Sub TextBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyTab
            KeyCode = 0
    End Select
End Sub
Change TextBoxName to the name of your text box.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Disable Tab Off a Text Box

Post by Leesha »

Perfect! Thanks so much!!