Recognizing Tab Key

Recognizing Tab Key

I have a text box that updates a memo field in Access.I would like to give the users the ability to insert tabs.The KeyDown and Keypress will not recognize the tab key.

Inserting tab characters is a bit of a pain because the Tab is intercepted by Windows. What I would suggest that you do is to allow the user to press Control-T to put in a tab, which you can intercept (Ascii Code = 20). Then set the SelText property of the text box equal to a certain number of spaces rather than using the ASCII Tab character.It is possible to put Tab functionality into a textbox. But to do so you have to turn off the TabStop property for all controls on your form, thus breaking the ability for your users to tab from control to control. Since tabbing between controls is part of the Windows standards you should think hard about your app’s need to do this before employing this sort of functionality.Code to toggle TabStop state looks like this:

Sub ChangeTabStops (flag As Integer)’if flag = False this sub turns off all the tab stop properties on all the’controls on Form1’Passing flag = True turns the tab stops back onDim i As IntegerOn Error Resume Next  For i = 0 To Form1.Controls.Count – 1   ‘ Use the Controls collection    Form1.Controls(i).TabStop = flag         ‘set the Tabstop property to either True or False  NextEnd Sub
If you’re not happy with the default size of the Tab’s space you can use the SendMessage API call along with the EM_SETTABSTOPS constant to change it. Be careful on the declare for this because the 32-bit version is a lot different than the 16-bit one.

See also  Monetize TikTok For Your Business

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist