Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Tab in Text Box > < Embedded Report | Account Balances 1 >
Tab in Text Box
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   3 years ago

Simulate Tab Spacing Functionality in Text Boxes


 S  M  L  XL  FS  |  Slo  Reg  Fast  2x  |  Bookmark Join Now

In this Microsoft Access tutorial, I'm going to teach you how to simulate tab-like spacing functionality in your text boxes.

David from Danville, Virginia (a Silver Member) asks: Is there any way to use the TAB key in Microsoft Access text boxes like you can in Word? Looks like text boxes don't allow tab characters, it just moves the focus to the next field. I'd like to keep my source code samples and other documents in Access. Plus I get spec sheets from one of my suppliers as plain text with a lot of tabbed columns and I'd like to store them in Access too. Any ideas?

Members

Silver members will learn how to actually calculate the position of the cursor so we can place the spacing at the exact location without using SendKeys. We will also turn this into a global module so it's easily used from any form.

Gold members get an extra additional bonus Extended Cut where we will actually calculate tab stops every 4 spaces. This way you're not just inserting 4 spaces everywhere. If you're 3 characters in on the line, a tab will only insert 1 space. We'll calculate it based on position. Plus you can download the database, and get the code from the Code Vault (along with tons of other stuff).

Silver Members and up get access to view Extended Cut videos, when available. Gold Members can download the files from class plus get access to the Code Vault. If you're not a member, Join Today!

Prerequisites

Links

Recommended Courses

Learn More

FREE Access Beginner Level 1
FREE Access Quick Start in 30 Minutes
Access Level 2 for just $1

Free Templates

TechHelp Free Templates
Blank Template
Contact Management
Order Entry & Invoicing
More Access Templates

Resources

Diamond Sponsors - Information on our Sponsors
Mailing List - Get emails when new videos released
Consulting - Need help with your database
Tip Jar - Your tips are graciously accepted
Merch Store - Get your swag here!

Questions?

Please feel free to post your questions or comments below or post them in the Forums.

KeywordsTab in Text Box in Microsoft Access

access 2016, access 2019, access 2021, access 365, microsoft access, ms access, ms access tutorial, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #learn, #lesson, #training, #database, Allow tabs in Long Text Boxes, typing the tab character into text boxes, Tab in Text Box KeyDown, KeyCode, KeyDown Event, monospaced fonts, proportional fonts, sendkeys

 

 

Comments for Tab in Text Box
 
Age Subject From
3 yearsYOUR DB VAULTEduardo Benaim
3 yearsTab in TextBoxJohn Davy

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to Tab in Text Box
Get notifications when this page is updated
 
Intro In this video, I will show you how to add tab-like functionality to text boxes in Microsoft Access forms using a simple VBA solution. You'll learn how to intercept the Tab key, prevent it from moving to the next field, and insert spaces in place of a Tab character, which is especially useful for organizing code samples or tabular data stored in Access. I will walk you through modifying your form settings, writing the required VBA code, and using the SendKeys command to simulate tab stops within your text boxes.
Transcript Today, I'm going to teach you how to add tab-like functionality to your text boxes in Microsoft Access.

Today's question comes from David in Danville, Virginia, one of my Silver members. David says, is there any way to use the Tab key in Microsoft Access text boxes like you can in Word? Those text boxes do not allow Tab characters. It just moves the focus to the next field.

Yep, that's generally how they work. I'd like to keep my source code samples and other documents in Access. Plus, I get spec sheets from one of my suppliers as plain text with a lot of tab columns, and I'd like to store them in Access. Any ideas?

Well, David, you're right. That's how Access treats the Tab key. It moves you to the next field. But with a little bit of VBA - a couple lines of code - we can intercept that Tab key and replace it with spaces, which will act very much like you want with tab characters.

Let me show you what I'm talking about.

Before we get started, this is going to be a developer-level video. We don't need a lot of code, maybe about six or seven lines, but you need to know where to put them. I'm going to show you where to put them, but if you've never done any VBA programming before and you want to learn, go watch this video for a few minutes first. It's about 20 minutes long and teaches you everything you need to know to get started programming in VBA.

We're going to need an If Then statement, a couple of them actually, to check to see what key is pressed and all that stuff. So if you've never used an If Then before, go watch this.

And we're going to use the SendKeys command. I'm not a huge fan of SendKeys, but once in a while it's got its purpose. Like I said, it's the king of the good enough sometimes functions. I'm going to show a better method in the extended cut, but that involves a lot more programming, but SendKeys will get the job done. So go watch this if you've never used SendKeys before.

These are all free videos. They're on my YouTube channel. They're on my website. Go watch them and then come on back.

Here I am in my TechHelp free template. This is a free database. You can download a copy from my website. Let's say for each record in here - each customer, whatever it is - we want to store a bunch of text, and that text has a bunch of tab columns in it.

I personally like to store my source code samples in an Access database. So if you have something like this, where's my global mod? There it is. You want to take your little source, your little functions and stuff, and store these in your table. That's kind of what David's looking to do.

The first thing I'm going to do is let's pretend this is, I know it's my customer form, but we're just going to pretend it's my source code form. I'm going to delete most of this stuff. Delete that, delete this. We're going to use this box here to store our text.

Now, let's do that. The first thing is save this, open it back up again.

If I take some source code like this, let me copy that to my clipboard, and I'll come back in here and paste it in. That's not too bad.

But when you're working with tabs, especially, a monospace font is better than a regular proportional font because each character will take the same amount of space going across in columns.

The first thing I'm going to do is switch this guy to a monospace font like Courier New. There you are, Courier New. Now you'll be able to see that it's more lined up in columns. That's the first step I do whenever I'm working with columns, especially source code.

Another thing I want to note is to make sure you're using plain text and not rich text because rich text boxes are going to have some hidden characters in there like divs or if you've got font changes, color changes. You can't see that in the actual characters, but it'll be in the box behind that. So this will only work with plain text.

Now normally, let's say you want to add something in here. You want to make some modifications, so you come in here, press Enter, then you want to tab over under that DoEvents. Tab and it moves you to the next record. Why is that? When you press Tab in Access, the form is going to grab that and move you to the next field. The Tab character is actually processed by the form itself, not this text box.

So we have to intercept that character at the form level. That's the trick. No key event in here will properly handle that Tab key. Trust me, I've tried them all.

What you have to do is use a form event. We're going to use the form's Key Down event, right here on Key Down. But before you do that, you have to tell the form that it's okay to intercept those key presses. There's a property down here called Key Preview. Turn that on. That's important. Don't forget that.

Once Key Preview is on, now the form can handle the Key Down events before the text box gets them. Now come up here to the form's Key Down event. Where are you? Right there. On Key Down. Now we're in the form's Key Down event.

As a side note, if you want to learn more about that Key Preview property, I talk about it more in my Help System video where I teach you how to press F1 to get context-sensitive help. We do something similar with Key Preview there.

In here, what does Key Down give you? It gives you a KeyCode and a Shift. We're going to ignore Shift for now. Shift just basically tells you if the user is holding down the Shift, Ctrl, or Alt keys. We don't need that for this example. KeyCode is the ASCII code or whatever key is pressed.

Let's take a look at what that looks like. I'm just going to message box KeyCode right now. You'll see what the characters are that are coming in. Ready? Hit Save. Let me go back over here. Close this. Open it up.

We're going to come in here. I'm going to press the letter A. Look at that. 65. I'm going to press the letter B. Look at that, 66. I'm going to press the Tab character. Nine. So remember that. Tab is nine. Then it went to process it. It moves.

The first thing I want to do is note that Tab is nine. Tab equals character nine.

Now what I'm going to say is, if KeyCode equals nine, then the user pressed the Tab key. Do some stuff. End If. Everything else I don't care about. I only want nine.

Maybe in here, we'll message box "Tab is pressed". Come back out here. Type in some stuff. I'm typing. I'm typing. I'm typing. I'm going to press Tab. There's "Tab is pressed." And then it continues.

The next thing I want to do is stop that actual Tab from processing. Let's get it to not go to the next field. How do you do that? In here, we can trick it. At the very end of this block, we can say KeyCode equals zero. That's a trick. If you say KeyCode equals zero, it essentially nullifies that key press.

Watch now. I'll come back in here. I'll go type, type, type, type, type. I'll hit Tab. It knows the Tab key was pressed, and then it stops. It doesn't do anything. So we can handle that Tab key now however we want.

Now, I don't want the Tab to happen on just any field. Right now the form is looking at everything that's pressed in this entire field. I only want this to happen if the user is in this field. This guy's called Notes. That's the name of this box. It's Notes. Let's make sure. Could be... Yeah, Notes.

How do I tell what field the user's currently in? That's a special thing. It's called Screen.ActiveControl.Name. If that equals Notes, then do some stuff. Again, we'll put the KeyCode inside of there, and then End If. So user is in the Notes field. Otherwise, ignore it. They've got to hit a Tab key, and they've got to be in the Notes field.

Let's save that now. I'll put the message box back in there.

Ready? So if I come back over here, let's close it and open it. Come in here. I'll do some type and type and type and type and type and type and Tab. There's my tab. It ignores it.

How about up in here? Tab. It ignored it and went to the next field, which is what it's supposed to do there.

Now, as far as the Tab character goes, whenever you copy and paste from the Visual Code Editor and such, it just replaces it with space characters. That's what we're going to do here. It's not perfect, but for what David wants to do and what I do most of the time, it's good enough. Each of these tab characters gets replaced with one, two, three, four spaces. So that's what we're going to do. We're going to insert four spaces wherever that cursor happens to be.

How do we add characters? The easiest way is with a little SendKeys, actually. We're going to go SendKeys. You can put in here " " if you want to (four spaces). Wait if you want to wait until these are done before continuing processing. Yeah, let's wait. Get rid of that extra line. Save it.

Ready? I'm going to come up here. I'm going to hit Tab. Boom. Look at that. Four characters. Now I can continue typing. Message box. I enter Tab, Tab, more stuff here. See that? Enter Tab, Tab, Tab, another Tab here, and so on. You can use it in the middle here too like Tab, Tab, Tab. It'll add four characters wherever you happen to be.

Is it perfect? No. But it's good enough. You want to just come in here and make some changes. So there you go. That's not that hard. It's about, what, really tentatively, it's one, two, three, four, five, six lines of code in the right spot.

You have to know to turn on the Key Preview. There you go. That's how you do it.

Like I mentioned in my SendKeys video, SendKeys isn't perfect. I'll use SendKeys if it's something that is only running while the user is actually typing. I do not use SendKeys for anything automated, like an event that runs.

In the extended cut, we're going to get rid of the SendKeys. We're going to use some actual real code to figure out the position that we are inside that text box and put the code, put the tabs there, put the spaces there. We're going to make it a global function so you can use it from any form. Right now, it's kind of locked onto that form and to that field, but by making it a global function, we can use it anywhere in the entire database with just a one line of code for that text box or that form.

I have not done one of these in a while. I'm going to have a Gold member bonus. Instead of just adding four spaces, we're going to use actual tab stops. It will count the number of spaces that it needs to the next actual tab stop. That's a lot more difficult. That's why it's for the Gold members. That's a bunch of code. That took me all morning.

Check it out. Silver members and up get access to all of my extended cut videos. You want to learn really cool stuff? They're all in the extended cut videos.

If you have fun learning this stuff, I have lots of Access Developer lessons available. I take you from the beginning right on through up to the advanced stuff. We go through all kinds of topics. I have 43 - as of today, 43 different levels available. Each one's at least an hour long. Some are around four hours long.

We have lots of fun learning and would like you to join us. If you have any questions, post them down below.

That is going to be your TechHelp video for today. I hope you learned something. Live long and prosper, my friends. I'll see you next time.
Quiz Q1. What happens when you press the Tab key in a standard Microsoft Access text box by default?
A. It inserts a Tab character into the text box
B. It deletes the current line of text
C. It moves the focus to the next field on the form
D. It triggers the form's After Update event

Q2. Why would you want to use a monospace font like Courier New in an Access text box when storing source code or data with columns?
A. Monospace fonts display all characters at the same width, making columns line up
B. Monospace fonts are required for plain text data
C. Monospace fonts enable color coding in text boxes
D. Monospace fonts automatically add tabs between words

Q3. Which property must be set to True on the form to allow handling key press events before controls receive them?
A. Key Allowance
B. Key Preview
C. Tab Order
D. Control Box

Q4. Which VBA event should you use on the form to catch and handle the Tab key press?
A. Form_AfterUpdate
B. Form_Load
C. Form_KeyDown
D. TextBox_BeforeTab

Q5. What value does the KeyCode variable contain when the Tab key is pressed in an Access form?
A. 65
B. 0
C. 13
D. 9

Q6. Why is it better to use plain text rather than rich text for the text box in this solution?
A. Rich text displays text with random font sizes
B. Rich text can contain hidden formatting characters that interfere with tab processing
C. Plain text automatically saves to the database
D. Plain text disables the Tab key

Q7. What does the line "KeyCode = 0" accomplish in the KeyDown event procedure when handling the Tab key?
A. It prevents all input from the keyboard
B. It stops the default Tab key action from moving to the next field
C. It resets the form to its default state
D. It sets the focus back to the text box

Q8. How does the SendKeys command help in this solution?
A. It sends tab characters to all controls on the form
B. It allows inserting a custom string (such as four spaces) at the cursor position
C. It triggers the form's submit event
D. It automatically saves the record

Q9. What condition is checked to ensure the custom tab behavior only occurs when the correct text box is active?
A. The text box must be empty
B. The text box name must match a specific name (e.g., Notes)
C. The text box must be read-only
D. The Shift key must be pressed

Q10. What is an important limitation of using SendKeys for automated processes in Access, as discussed in the video?
A. SendKeys does not work with plain text boxes
B. SendKeys should not be used for automated events since it can cause unpredictable results
C. SendKeys automatically disables user input
D. SendKeys adds too many spaces

Q11. What is a downside of the simple solution presented for handling tab functionality in Access text boxes?
A. It only works on subforms
B. It adds a fixed number of spaces rather than actual tab stops
C. It deletes any existing content before inserting tabs
D. It disables all other keyboard shortcuts

Q12. In the more advanced solution hinted at for Gold members, what improvement is made over the simple solution?
A. It removes support for tabs entirely
B. It inserts the exact number of spaces needed to reach the next tab stop rather than always four spaces
C. It only works if the Caps Lock key is on
D. It inserts random spaces for each tab press

Answers: 1-C; 2-A; 3-B; 4-C; 5-D; 6-B; 7-B; 8-B; 9-B; 10-B; 11-B; 12-B

DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks.
Summary Today's TechHelp tutorial from Access Learning Zone covers how to add tab-like functionality to text boxes in Microsoft Access.

This question comes from someone who wanted to know if it's possible to use the Tab key within Access text boxes in the same way you might in Word. As you have probably noticed, pressing Tab in an Access text box simply moves the focus to the next field on the form, not allowing for a Tab character within the actual text. This can be frustrating, especially if you want to store source code samples, documents, or plain text data with tabbed indentation, such as supplier spec sheets or structured content with columns.

By default, Access does not support actual Tab characters inside its text boxes because the form intercepts the Tab key to facilitate navigation. However, with a little bit of VBA, we can create a workaround to simulate this behavior using spaces in place of the actual Tab character.

First, let me preface that this tutorial has a developer focus, but the code needed is minimal - only about six or seven lines. Even if you are new to VBA, I'll guide you through where to place the code. If you have never programmed with VBA before, I recommend that you spend a few minutes with one of my introductory videos, which will get you up to speed on the basics of VBA, using If Then statements, and the SendKeys command.

To prepare, start by setting up your form as needed. In my example, I use the TechHelp free template database, which you can download from my website. Imagine that, for each record, you want to store a block of text, such as a code sample or other content requiring tabs for indentation. It is best to use a monospace font, such as Courier New, for your text box, so columns and indents display correctly. Also, make sure your text box is set to plain text, not rich text. Rich text fields can contain hidden formatting that may interfere with this technique.

Now, here is the main challenge: when you press Tab in Access, the form, not the text box, registers the keypress and shifts focus elsewhere. This means you must use an event at the form level to capture Tab keystrokes. The best way is to use the form's Key Down event. Before you can do that, you need to enable the Key Preview property on the form. This allows the form to process key events before any control does.

With Key Preview enabled, open the form's Key Down event in VBA. The Key Down event gives you two parameters: KeyCode and Shift. For our purpose, all we care about is KeyCode, which represents the key pressed. For reference, the Tab key is character code 9.

Within the event code, you'll need to check if the key pressed is the Tab key (KeyCode 9), and, importantly, if the focus is currently inside the specific text box where you want this behavior (for example, the "Notes" field). The ActiveControl object can tell you where the user currently is.

If the user presses Tab while in the designated text box, you want to block the default behavior. You can do this by setting KeyCode to zero, which tells Access to ignore the original key press. Now you are free to simulate typing spaces in place of the Tab character. The simplest way to do this is to use the SendKeys command to send four spaces into the text box at the cursor location. This is not a perfect swap for an actual Tab character, but for most practical purposes like code samples or text columns, four spaces per Tab is good enough.

As you test this, you'll find that pressing Tab now inserts four spaces wherever the cursor is, allowing you to indent text as needed without shifting to the next control on the form. You can continue editing, inserting, or pasting content as usual. This solution is quick and effective, relying on only a handful of lines of code.

However, keep in mind that SendKeys is not a perfect solution for every scenario. I only recommend using SendKeys when the code executes in direct response to user input, such as typing. For anything automated, SendKeys can be unpredictable.

If you are looking for a more advanced and robust solution, in the Extended Cut of this lesson, I show how to replace SendKeys with real VBA code that determines the cursor's precise location in the text box and inserts the appropriate number of spaces programmatically. We also make this solution portable by wrapping the logic in a global function, which means you can enable the same tabbing behavior on any text box, on any form throughout your entire database with just a single line of code. For those interested in going even further, the Gold member bonus lesson demonstrates implementing true tab stops, where the number of spaces inserted aligns with the next tab stop, similar to how editors handle Tab characters. This requires more advanced code but provides even closer functionality to what you might expect from a text editor.

If you are interested in a thorough learning experience, I offer a broad range of Access Developer lessons that guide you from beginner through advanced topics, each with hours of carefully explained instruction. Feel free to ask questions below the video.

You can find a complete video tutorial with step-by-step instructions on everything discussed here on my website at the link below. Live long and prosper, my friends.
Topic List Adding tab-like functionality in Access text boxes
Using VBA to intercept the Tab key
Setting a monospace font for text columns
Switching Access text boxes to plain text
Enabling form-level Key Preview property
Handling the form Key Down event
Identifying which control is active with Screen.ActiveControl
Checking for the Tab key with KeyCode
Suppressing Tab key default behavior using KeyCode = 0
Inserting spaces with SendKeys in response to Tab
Limiting Tab handling to a specific text box
 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 2/16/2026 10:11:30 PM. PLT: 1s
Keywords: TechHelp Access Allow tabs in Long Text Boxes, typing the tab character into text boxes, Tab in Text Box KeyDown, KeyCode, KeyDown Event, monospaced fonts, proportional fonts, sendkeys  PermaLink  Tab in Text Box in Microsoft Access