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 > SendKeys < Follow Hyperlink | Fill In PDF >
SendKeys
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   4 years ago

The King of Good Enough Sometimes Functions


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

In this Microsoft Access tutorial, I will teach you about the SendKeys function. You can use it to make your VBA code act just like someone is typing at the keyboard. It has pros and cons. We'll address some of those in this video, and I'll show you a few examples. I'll explain when you could use it, and when you should not use it.

Pre-Requisite

Recommended Course

Notes

  • Shift +
  • Ctrl ^
  • Alt %
  • Enter ~
  • Remember to specify lowercase letters, otherwise you get Shift-whatever!
  • {LEFT 15} means press the left arrow key 15 times

Links

Nitpick

  • Yes, yes, I know. SendKeys is technically not a function. It doesn't return a value. It is a statement or procedure.

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.

Keywords

access 2016, access 2019, access 2021, access 365, microsoft access, ms access, ms access tutorial, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #learn, #lesson, #training, #database, #fasttips, Using the SendKeys Method, What are SendKeys in VBA, send keystrokes anywhere, sendkeys to another application, sendkeys not working, automate

 

 

Comments for SendKeys
 
Age Subject From
3 yearsBetter way for a msgboxThomas Gonder
3 yearsSendKey Compile ErrorRonald de Boer
4 yearsSendKeys and ExcelMark Pierce
4 yearsre Evil SendKeysMaggie M

 

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 SendKeys
Get notifications when this page is updated
 
Intro In this video, we'll talk about the SendKeys function in Microsoft Access and how it works within VBA to simulate keyboard input. I'll show you common examples of using SendKeys to input data into forms or work with other applications like Notepad, discuss why it's usually not the best solution for database automation, and share tips for situations where it's just "good enough." You'll also see why SendKeys is considered unreliable for critical tasks and learn some better alternatives for updating form values.
Transcript Welcome to another Fast Tips video brought to you by AccessLearningZone.com. I am your instructor, Richard Rost.

In today's video, we're going to talk about SendKeys. I'm going to show you how to use the SendKeys function in Microsoft Access. It is the king of the "good enough sometimes" functions.

So, what is SendKeys? Well, SendKeys is a function in VBA that allows your code to act just like someone is sitting at the keyboard. You can tell SendKeys to type in "RICHARD," and it will send "RICHARD" as if someone was typing it right at the keyboard. That sounds pretty cool.

The problem with SendKeys is that a lot of people, especially inexperienced Access programmers (and I'm guilty of this), tend to use it in situations that they really shouldn't because they don't know better. I did this for years. When I first started my current database, over 20 years ago, it was common to use SendKeys all over the place.

So, don't think I'm picking on you if you use SendKeys. I was in the same boat. I used to do it myself. In fact, I've got an "Evil Access Stuff" list on my website. I put a link down below for you. I have all kinds of things like "Don't use spaces in your object names," that kind of stuff. And I've got SendKeys down here in the "frowned upon" list. In other words, yes, you can use it once in a while, but don't rely on it heavily.

SendKeys: I call it the king of the "good enough sometimes" functions because, yes, it's good enough once in a while. If you want to throw a SendKeys in there here and there, go ahead. It does have some valid uses, and I'll talk about those in this video. But never rely on SendKeys for anything mission-critical. If you've got an application that absolutely has to work 100 percent of the time, don't use SendKeys. It's very unreliable. If it's something you're going to click on and watch it happen and maybe do something quick, fine, use SendKeys.

Usually, you rely on SendKeys when you don't know the proper way to do something, or building the code to do something properly is just a lot of work. And if you've got some little thing you want to do once in a while that isn't really important, but you want to quickly automate it with SendKeys, fine. I'm guilty of that myself sometimes.

Let's take a look at an example. Next, I'm going to show you what I used to do myself and what I see a lot of people do when they send me their database or their code to look at. This is what a lot of people do, and you might be guilty of this yourself.

Before we get started, it goes without saying this is obviously a VBA lesson. So if you've never done any VBA programming before, go watch this video, and then come back.

Here I am in the TechHelp free template. This is a free database. You can grab a copy off my website if you really want to. You'll find links to this and all the videos that I mention down below in the description.

The number one thing that I see (that I used to do) is using SendKeys inside of Access itself to send data somewhere. You should never have to do this, but if you don't know any better, like I didn't 20 some years ago, it's common for people to say they have a list box or a continuous form list like this. They open up a customer record, and you want to send some data in here. If you don't know how to do it properly, you resort to SendKeys (I used to).

For example, in here I have an "Open Customer" button, or the double-click event runs this thing called OpenCustomer. It just does DoCmd.OpenForm that customer form. Now, if you don't know how to set values in a form that you just opened, you might do this: DoCmd.GoToControl. That sends the focus to a particular control. Let's go to the CustomerSince field. Let's pretend CustomerSince is like a last appointment date, whatever. You want to open the customer's record up and set their last contacted date to today's date. So now the cursor is sitting on the CustomerSince field.

Let me show you. We'll do this step by step. If I open up a customer now (William Riker), click, GoToControl sends the focus right there. Now you could use SendKeys to type in the date. How would you do that? Well, you come in here and you say SendKeys, and there are two parameters: the string of characters you want to send, and whether you want to wait for them to finish before continuing on with the next line of code. I almost always say use TRUE. The default is FALSE, which is not ideal.

So, let's SendKeys today's date, comma TRUE. Save it. Let's go back over here. Let's close this and let's open it back up again, click, and see that? It just sent the keys right in there. It's a simple, easy way to do that if you don't know the best way to do it (which I'll show you real quick). You don't want to use SendKeys if you can avoid it. Generally, 99.999999 percent of the time in Access itself, you're not going to use SendKeys.

Really, the only time I ever use SendKeys is when I want Access to control another application, which we'll talk about in a few minutes. But to do this, there are a couple of different ways you could do this. A better way is to say: open the form, and then say Forms!CustomerF!CustomerSince = Date. That's it. And I like to throw a Forms!CustomerF.Refresh in there. Me.Refresh is the current form that you're on, which is the one that's calling it, but this will send the date to that field and then refresh the form so it saves it.

If you want to learn more about that notation, that Forms!CustomerF!FieldName, watch this video. I show how to get a value from an open form. You can also use it to set a value on an open form as well. So that's a better way to do it. The best way to do it, I think, is a lot more advanced. It's either using an SQL statement or a recordset, set the value first, and then open the form. That is a lot more advanced. I've got other videos for that. If you're interested, I'll put links down below to my SQL and recordset lessons. But the one I just showed you, that's perfectly fine. That works just great.

When I first started my database years and years ago, before I knew any better, I had a whole bunch of that in my database. I'd click a button, it would open a form, it would use SendKeys here. It would go to this field, SendKeys there. I literally had it so when it was filling in orders, it would open up the order form and it was all SendKeys. It would go to this field, type in the order date, go to this field, type in the description, literally come down here and start typing in product information. It worked. It worked fine 95 percent of the time.

But the problem with SendKeys is it's unreliable, especially if you have other things running on the computer at the same time. Different things can cause the focus to switch to a different window. If another application happens to run while your database is running, you never want to have SendKeys in a database that does anything automatic. If you've got a timer that runs, like I've got a separate Access server set up that actually runs constantly and is doing stuff like sending emails and processing stuff, I got all the SendKeys out of that database because if anything else happens, another application pops up in the foreground, SendKeys will jump to there. So don't rely on SendKeys.

Again, it's cool for little tricks, like I'm going to show you here, but don't rely on it.

Let me show you another one. I mentioned earlier, you can use Access and SendKeys to open up other applications. Let's do an example of that. Let's go in here and in my Hello World button, right click, build event.

What we're going to do is, let's say you want to open up another application like Notepad, and we're going to send some information to Notepad. So how do we do that? Well, there's a command called Shell that you can use to open another program. You can open Notepad, Calculator, Word, whatever. If it's in the Windows path, if it's a Windows application, you don't need the full path to it. Otherwise, you do.

You just type in Shell. What's the file? Notepad.exe. Notepad.exe comes with Windows, so it's in the Windows path. You don't need the full C:\\ path. But if you're opening something like Word or Excel, you might need that.

Then, comma, there's a bunch of Windows styles. You can have it open hidden, you can have it open maximized, minimized, with or without the focus. In other words, is the cursor sitting there? I'm going to go with vbNormalFocus. So it's going to open as a normal window and it's going to have the focus. If it doesn't have the focus, you can't SendKeys to it.

So it's going to open up Notepad, put it in the foreground, and now I'm going to send some keys to it: SendKeys "Hi there. This is Access talking to Notepad", whatever, then comma, TRUE. You always want to do your comma, TRUE there so that SendKeys waits until it's done before it runs the next line of code. Here there is no next line of code, but a lot of times with SendKeys you want to send some stuff, do something else, send some more stuff, and so on.

Let's see if this works. Save it, close it, open it back up again, and click. There it goes. That's pretty cool.

You can send data from the database here, too. If you've got fields, if you do this from the customer form, you can say send first name, last name. If you want to make a little note or something, you can open up Calculator.

There's an example on Microsoft's website. I can't get their example to work, by the way. They have some old code on there. Let me show it to you.

Here's Microsoft's page for SendKeys, and I'll put a link down below in the link section. You can click on it. It's got two things: string and wait. There are a bunch of special keys. If you want to send a backspace, you use curly braces backspace. Caps Lock, all that stuff. In fact, that Caps Lock video, I'll mention it in just a minute. If you want to send a right arrow, the Print Screen key, all this stuff.

If you want to do Shift, you use a plus. So, like +A would be Shift+A. A little caret symbol, ^A would be Control+A. If you want to send an actual plus symbol, you put the plus inside of brackets. If you want an actual plus, put those inside of curly braces. There are a lot of weird rules. Again, I hardly ever use SendKeys.

They have an example down here. This code here, I can't get this to work. I've tried a couple times. This AppActivate doesn't seem to want to behave itself. So try this if you want. Let me know, post a comment down below if this works for you. Doesn't work for me. But generally, if you Shell a program like Notepad or Calc, and you use vbNormalFocus, it has the focus so you don't have to AppActivate it. I've never used that. I don't really care about it.

Sometimes, though, you do have to put a sleep delay in there, because sometimes the application, like Word or Excel, will take a second or two, depending on the speed of your computer, to open it. If the application isn't finished opening, you can't SendKeys yet because the app isn't loaded. Notepad opens right away, so it just accepts whatever you send to it.

Now again, SendKeys is the king of the "that's good enough" functions because that's not the best way to do that. If you want to create a text file from Access, there are file I/O functions you can use to open, create, write, read. I cover all the file I/O functions in my Access Developer 30 class. However, you've got to know how to read and write text files to do what we just did with SendKeys in 10 seconds. So this is without a doubt an easier solution to code. And if it's just something that you want to sit here, click a button, and put some text in Notepad, fine, it works great. But don't rely on it for anything business critical.

I've got some other examples I'm going to show you here. For example, another video I did lets you turn the Caps Lock, Num Lock, and Scroll Lock keys on or off from VBA using SendKeys. Again, it's a good enough solution. If you want to click a button and toggle off your Num Lock key, that's great. But again, it's not the best solution. There are Windows API calls you can use, and I show those in the members' versions. They're a little more advanced. But again, good enough solution: click a button, use SendKeys, turn on Caps Lock.

Another good enough use for it is to fill in a PDF form. In fact, one of the reasons I want to do this SendKeys video first is because tomorrow's Fast Tip is going to be on this. I get asked this all the time. At least once or twice a week, someone asks, "Is there any way to use Access to take the customer data and fill in a PDF form with it?" Yes, you can. There are two ways to do it. Again, there's the good enough way, which I'm going to show you tomorrow, and there is the better way, which involves some crazy programming and you have to have a paid copy of Acrobat. Personally, I've never done it, but I've seen code for it. We'll talk about that in tomorrow's video.

This is one of the most asked things I get: how to do this. So I'm going to put together a video on how to do this, but I want to teach you SendKeys first so you understand not to rely on SendKeys.

So there you go. SendKeys. Love it, hate it, use it once in a while, but don't rely on it. It's going to stay on the evil list under "frowned upon," but I'm going to update that and put a link to this so at least it explains why it's frowned upon. Now you know why I frown upon it. I have to change my face over here so I have a little frowny face. There, frowned upon.

Do you remember those little labels they used to have that you could put on medicines and such, or like bleach and stuff under your kitchen cabinet or medicine cabinet, the little green stickers to scare kids not to drink this stuff? That's what that sticker reminds me of.

So, there is your Fast Tip for today. I hope you learned something. I'll see you tomorrow and we'll do some PDF filling and stuff.
Quiz Q1. What does the SendKeys function in VBA do?
A. It sends keystrokes to applications as if they were typed at the keyboard
B. It recompiles VBA modules
C. It secures Access databases with a password
D. It creates new Access forms automatically

Q2. Why is SendKeys considered unreliable for mission-critical applications?
A. It can only send numbers and letters
B. It is very slow
C. Other applications can interfere with focus, causing SendKeys to act on the wrong window
D. It deletes files if used incorrectly

Q3. When is it acceptable to use SendKeys, according to the video?
A. For business-critical automation
B. Whenever possible as it is always reliable
C. For quick automation of nonessential tasks you are manually watching
D. To replace all data entry in Access forms

Q4. What is a preferred method to set a field's value in an open form instead of using SendKeys?
A. Rewriting the VBA engine
B. Using Shell to open Notepad
C. Setting the field value directly using Forms!FormName!FieldName = Value
D. Exporting to Excel and reimporting

Q5. Which parameter in the SendKeys function ensures execution pauses until keys are sent?
A. "Delay"
B. "Pause"
C. TRUE for the Wait parameter
D. "vbNormalFocus"

Q6. In which case does the video author find SendKeys most appropriate within Access?
A. Automating core financial reporting
B. When controlling other applications like Notepad for simple output
C. When running daily sales reports
D. Populating critical customer records that must always be accurate

Q7. What must you ensure when using SendKeys to communicate with another application like Notepad?
A. The application is minimized
B. The application is in the background
C. The application is in the foreground and has the focus
D. You have used AppActivate with every application

Q8. What is a key risk with using SendKeys in databases or processes that run automatically (like with timers)?
A. It sends the wrong keys by design
B. It may interact with the wrong window if the focus changes
C. It corrupts Access databases
D. It disables macros

Q9. How can you send special keys like Shift, Ctrl, or Alt with SendKeys?
A. Use quotation marks around the keys
B. Use +, ^, or % symbols before the character
C. Only with the API, not SendKeys
D. With Excel integration only

Q10. According to the video, what is an alternative to using SendKeys for writing text to a file?
A. Microsoft Paint
B. File I/O functions to create/write/read text files
C. Manually copying and pasting text
D. Using the Access Report wizard

Q11. Why does the author keep SendKeys on his "frowned upon" or "evil" list?
A. It is not supported on newer Windows versions
B. It is always slow
C. It is too unpredictable to trust for important business processes
D. It requires advanced security permissions

Q12. For toggling keys like Caps Lock, Num Lock, and Scroll Lock in VBA, how does SendKeys fit in?
A. It is the only way to do it in VBA
B. It is a "good enough" but not the best solution
C. It never works with these keys
D. It always requires administrator access

Q13. What is the main advice from the video regarding relying on SendKeys?
A. Use it often to save time in complex solutions
B. Only use if there is no other method available and only for simple, noncritical tasks
C. Disable it in your database options
D. Always set the wait parameter to FALSE

Q14. What does the video suggest if you need to fill in PDF forms from Access?
A. Always use SendKeys for all PDFs
B. Use either SendKeys for a quick solution or advanced code with paid Acrobat for a robust solution
C. Only use Notepad integration
D. It is impossible to do from Access

Answers: 1-A; 2-C; 3-C; 4-C; 5-C; 6-B; 7-C; 8-B; 9-B; 10-B; 11-C; 12-B; 13-B; 14-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 video from Access Learning Zone explores how to use the SendKeys function in Microsoft Access. I'm going to walk you through what SendKeys is, why it can sometimes be useful, and why you need to be cautious about relying on it in your projects.

First, a bit about what SendKeys actually does. SendKeys is a function in VBA that lets your code mimic the actions of someone typing on a keyboard. For example, you could tell the computer to "type" the word RICHARD, and it would be as if a person was typing those letters manually. This might sound like a useful tool at first glance.

However, SendKeys has developed a reputation as a function that many novice programmers use in scenarios where it doesn't really belong. I speak from experience here—I used to depend on it heavily myself, especially early in my programming days over twenty years ago. On my website, I keep an "Evil Access Stuff" list, which you might find helpful if you're interested in learning about programming practices to avoid. SendKeys earns a spot there, not because it's always bad, but because it should only be used sparingly when there are no better alternatives.

I often call SendKeys the king of "good enough sometimes" functions. It's the sort of tool that can be fine for quick tasks that aren't critical to your database, but you should never use SendKeys for anything business-critical or where reliability is essential. A situation where you're just automating a button click for convenience might be a reasonable use case. But if your application has to work perfectly every time—and especially if you want your code to run unobserved—SendKeys is simply too unreliable.

Programmers usually turn to SendKeys either because they don't know the preferred way to accomplish a task or because writing the proper code seems like too much work for a small payoff. There are moments when you just want to automate something quickly, and in those cases, using SendKeys can be acceptable. I've been guilty of grabbing it for convenience as well.

Let me share a common example. In Microsoft Access, a typical mistake is to use SendKeys to push data into a field in a form. For instance, imagine you have a continuous form or a list box, and you want to open a customer record and automatically fill in a specific date, like setting their last contacted date to today. Someone new to VBA might open the form, move the focus to a field such as CustomerSince, and then use SendKeys to type in today's date. This seems like an easy solution, especially since the SendKeys function can specify which text gets "typed" and whether to wait for the action to finish before moving on.

But this is not the recommended method. In almost every case within Access, there are far better ways. The preferred approach is to directly assign the value to the field in your code, for example, by referencing the form and the specific field using the Forms!FormName!FieldName syntax. You can even refresh the form to save the value immediately. This method is more reliable and doesn't depend on simulating keyboard input, which can easily be disrupted by other activity on the computer.

If you're interested in learning more about using that notation to get or set values in forms, I have a separate lesson covering this topic in more detail. For even more advanced techniques, such as using SQL statements or recordsets to update data before opening a form, there are additional lessons available on my website.

I used to fill in entire order forms using SendKeys: moving from field to field, sending key presses to enter order dates, descriptions, and product details. It worked most of the time, but every so often, if the computer I was using became busy or another program momentarily grabbed focus, SendKeys would misfire. For this reason, you should never rely on SendKeys where other applications might interfere or in any process that needs to run automatically and reliably. It's simply too risky when anything else running on your system could steal the focus and redirect the keystrokes.

However, one scenario where SendKeys can still be useful is when controlling an external application from Access. For instance, you might want to open Notepad and automatically type some text there. You can use the Shell command in VBA to launch external programs such as Notepad, Calculator, Word, or Excel. For programs that are in the Windows path, you can use just the file name without needing the full path. With Shell, you can control how the program opens—normal size, minimized, maximized, or with focus. Having the right window in focus is important because SendKeys will only work if the intended window is active.

Once the other application is open and focused, SendKeys can "type" the text you specify. This is handy if you want to quickly transfer some information from your database into a text editor, for instance. If you are extracting data from your database form fields, you can concatenate it and send it to Notepad or similar programs. There are some details you'll need to check, such as ensuring the application is fully loaded before sending keystrokes, so sometimes a delay (or sleep) in your code is necessary, especially with slower-loading programs like Word or Excel.

Microsoft provides documentation listing special keystrokes and symbols you can use with SendKeys, like backspace, Caps Lock, and arrow keys, as well as how to indicate key combinations such as Shift or Ctrl. Their documentation also explains using AppActivate if you need to switch the focus to a different window, although, in practice, if you open the application with Shell and vbNormalFocus, AppActivate usually isn't needed.

While SendKeys offers a quick and straightforward way to send information out to other programs, it has significant limitations. For example, if your goal is to write text out from Access, the better solution is to use file input/output functions to create and write to text files directly from VBA. I cover these techniques in my Access Developer courses. While file I/O is the best option for generating files programmatically, SendKeys can be the shortcut for simple, occasional actions where perfection is not mandatory.

Another fun example is using SendKeys to toggle keys like Caps Lock, Num Lock, or Scroll Lock from within Access. This might be a good enough answer if you just want a button to turn a lock key on or off for yourself, but again, it's not as robust as calling the appropriate Windows API functions (which I cover in the members' lessons).

A common request I get is whether Access can be used to autofill a PDF form with customer data. There are actually two ways to approach this. The first is a SendKeys-based "good enough" solution, which I'll be covering in my next video. The more advanced and reliable approach requires complex programming and a paid copy of Adobe Acrobat, and it's considerably trickier.

To sum up, SendKeys can be handy in limited circumstances, but you should avoid relying on it for important tasks in your Access projects. It's staying on my list of "frowned upon" practices, and now you know why. I hope today's Fast Tip helps you understand both the usefulness and the dangers of SendKeys in Microsoft Access.

For a complete video tutorial with step-by-step instructions for everything I've discussed here, visit my website at the link below.

Live long and prosper, my friends.
Topic List Introduction to the SendKeys function in VBA

Using SendKeys to simulate keyboard input in Access

Common beginner mistakes with SendKeys

Drawbacks and unreliability of SendKeys

Example of using SendKeys to enter data in a form

Alternative to SendKeys for setting form values

Using Shell to launch external applications from Access

Sending keystrokes from Access to external applications like Notepad

Explanation of SendKeys special keys and syntax

Using SendKeys with the wait parameter

Limitations of SendKeys when applications lose focus

Timing issues when sending keys to newly opened applications

Simple use of SendKeys to manipulate lock keys (Caps Lock, Num Lock)

Discussion of better alternatives to SendKeys

Appropriate situations for using SendKeys in Access applications
 
 
 

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/12/2026 11:51:41 PM. PLT: 1s
Keywords: FastTips Access Using the SendKeys Method, What are SendKeys in VBA, send keystrokes anywhere, sendkeys to another application, sendkeys not working, automate  PermaLink  SendKeys Function in Microsoft Access VBA