Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > CapsLockOn > < Help System | Suppress >
Caps Lock On Off
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   5 years ago

Turn Caps Lock, Num Lock, and Scroll Lock ON / OFF


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

Learn how to toggle Caps Lock, Num Lock, and Scroll Lock using Access VBA. We'll see how to turn them ON and OFF, and to read their current state so that you can either set them to ON, or set them to OFF.

Nancy from Swanton, Maryland (a Gold Member) asks: How can I use SendKeys to turn Scroll Lock ON. Right now, it only toggles between ON and OFF. I need to just set it ON when I click a button.

Members

I will show you how to turn these keys on and off WITHOUT using SendKeys!

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!

Links

Original Question Thread: https://599cd.com/a?27338
Intro to VBA: https://599cd.com/IntroVBA
Get Caps Lock: https://599cd.com/GetCapsLock
MS SendKeys Reference: https://tinyurl.com/y57rx8ba
Set Caps Lock: https://599cd.com/SetCapsLock

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.

 

Comments for Caps Lock On Off
 
Age Subject From
5 years64 Bit ErrorJeffrey Rainey

 

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 Caps Lock On Off
Get notifications when this page is updated
 
Intro In this video, we will learn how to use Microsoft Access VBA to check the status of the Caps Lock, Num Lock, and Scroll Lock keys and how to ensure they are turned on using the SendKeys command. I will demonstrate how to set up buttons in your Access forms that can turn these keys on instead of just toggling them, and show you how to check their current state using a custom function. Topics include reviewing the SendKeys command, copying prewritten code for detecting key states, and adding simple VBA routines to make your forms more responsive to keyboard settings.
Transcript Welcome to another TechHelp video brought to you by AccessLearningZone.com. I am your instructor, Richard Rost.

In today's video, I am going to show you how to turn on or off the Caps Lock, Num Lock, and Scroll Lock keys. Today's question comes from Nancy from Swanton, Maryland, one of my Gold members.

Nancy says, how can I use Send Keys to turn Scroll Lock on? Right now, it only toggles between on and off. I need to just set it on when I click a button.

Nancy posted her original question in my Access Forum. You can read the original thread if you'd like to. I'll put a link to it down in the link section below.

Basically, when she clicks a button, she wants to use Send Keys to turn the Scroll Lock on. She turns it on right there. Then she uses this Activate Keyboard Layout to change some settings on her keyboard. This is some third-party app she's using. Then she goes to a record, finds something, and turns it back off again.

The problem is, if it's already on, this here will turn it off and then back on again. If it's off, it'll turn it on and then off again. She wants this to just simply turn Scroll Lock on.

One thing we talked about is that I personally hate the Send Keys command. I used to use it a lot when I was first learning how to develop with Access years and years ago, but there is almost always a better way to do something without using Send Keys. I'll talk about that at the end of the video. For now, let's just get Nancy's code working.

Here I am in my TechHelp free template. You can download a copy of this template if you want to. It's on my website. I'll put a link to the free template down below.

Let's go into the Customer Form here because it's a nice big note field that I can use. Let's replicate what Nancy's got going on.

Let's go to Design View. If you've never done any programming before, go watch my Intro to VBA video first. If you've never done any VBA before, it's a good introduction for you.

Let's put a button in here. Command button right down here in the bottom. Cancel the wizard. Let's call this my Send Keys button. Right click, Build Event.

I'm not going to bother naming the button. We're not going to keep it around for long.

What am I going to do in here? What she's got going on is she's using the Send Keys command to send a key to the key, as if you typed it at the keyboard.

I'm going to do a whole separate video on Send Keys. How people commonly use it, why you shouldn't use it, and some different popular alternatives for the Send Keys command.

For example, if you want to go to the Notes field and then send some keys, you'd say this. You'd say Notes.setFocus. That moves the focus over to the Notes field. Then you can say Send Keys. Let's just send the key A.

CommitTrue says wait until the keys are done being pressed, like if they were being pressed at the keyboard, before continuing on with the next line. If you don't specify true there, Send Keys will just spew the information and it might continue running and mess things up.

Let's see what this does here real quick. Let's save this. Let's close it and reopen it, and I'll just hit the Send Keys button. See that? It just goes to the Notes field and sends an A.

You could send more stuff if you want to, send a whole bunch of strings like that. If you want to send some value, you could send the first name field. Send Keys puts Richard in there, so he gets it right out of there, puts it in there.

Nancy is using Scroll Lock, which is a special key. Scroll Lock, like that inside of curly braces. That will actually toggle the Scroll Lock on and off. If you send Scroll Lock, it's like you push the Scroll Lock key.

I'm going to use Caps Lock for the purposes of class, so you can see some differences of what's going on. Scroll Lock really doesn't do much and she's using it with a special program, but we'll use Caps Lock for class. It's the same exact thing. Num Lock works the same way too.

If you want to see a list of a whole bunch of special keys that you can use with Send Keys, I'll put a link down below to Microsoft's Send Key reference. Later on in the future, when I actually record my Send Keys video, I'll put a link down there too. I can edit it later. I haven't recorded it yet. It's not really high on my priority list because I don't really like Send Keys, but there's some stuff to be learned with Send Keys.

Anyway, let's use Caps Lock. Let's just toggle Caps Lock on and off. I just realized I got a goof in there. We're going to put that quotes right there. I'm not at the end here. That's much better.

Send Caps Lock, comma true. Let's see what happens. I'll hit Send Keys and nothing appears to happen because it goes there, but it didn't do much. But notice now, Caps Lock is on. See that? If I type in A, A, A, A, A on the keyboard, see I'm getting that. If I hit it again, Caps Lock went off. Click, and then click. It's going on and off.

The problem is, if you want to assist the user by hitting the button and then it always turns Caps Lock on, you have no idea what state it's at when you get here. You need some way of reading the keyboard state and saying, hey, is Caps Lock on or off? If it is on, don't do anything. If it's not on, turn it on. So there we need some code to read the keyboard state.

Now, this is where we get a little more complicated, but just follow along with me. I'll show you everything you need to know.

First, we have to create our own module to get the keyboard state. Now, I'm going to give you some code. You can either type it in yourself or you can copy it from my code vault. I'm going to make this a free page for everybody in my code vault. It's usually a paid feature, but this one I'm going to make for free.

OK, here it is in the code vault. It's called Get Key State. Now, I'm not going to explain how all of this code works. For now, just worry about copying this and pasting it into a module in Access.

I'll put a link to this page down below in the links section. Go here, copy everything from this option compare database all the way down to the bottom right there in front of usage. Copy all that stuff. Ctrl C, put it in your clipboard.

Now back in your database, go to Create and then Module. Regular module, not class module. Module will open up the VBA window like this. Get rid of this stuff in here because it's going to copy and paste in, and then paste like that. There's the code right out of the code vault. That's all you need to do.

Save this, Ctrl S, save this, then get, let's say yes here, sorry, call this the Get Key State Mod. Get Key State Module.

What is this? Basically, this is just some functions that allow you to determine whether or not Caps Lock is on - that's Get Caps Lock, Num Lock is on, or Scroll Lock is on. You don't have to worry about all this stuff up here. Sometimes it's like driving a car. You don't have to know how the engine works to drive the car. All we have to know right now is this, this, and this. So we're going to use the Get Caps Lock function right here.

Go back over to your customer form, right click, Design View. Let's make a button that will tell us whether or not Caps Lock is on.

I'm just going to take this guy. I'm going to copy this, copy, paste. State of Caps Lock. And I can spell today. Lock, oh, see.

Right click, Build Event. We're just going to say in here, Message Box Get Caps Lock. That's going to Message Box whatever this returns, Get Caps Lock. It'll be a true or a false.

Is Caps Lock on or off? Save it. Come back out here, let's close this, open it back up again. State of Caps Lock, false. Right now, it's off. Do you see it on down here? No.

Let's Send Keys. Boom. And now check it, notice right there, see. Caps Lock is now true. So my function's working, see, hit it, and now it's false.

Now we know how to read whether Caps Lock is on or not. Knowing that, up here in our little routine that Nancy's trying to run, all we have to do is read Get Caps Lock. If it's already on, don't send the Caps Lock key.

So right here, I'm going to say, if Get Caps Lock then do nothing, else, Send Keys, Caps Lock, end if.

Save it. Come back out here. Let's rename this button now from Send Keys. Let's rename this button to Turn Caps Lock on. It'll only turn it on now. Save it, close it, open it back up again.

Let's come in here and type. Caps Lock is off, turn Caps Lock on. Boom. Type, type, type, type, type, type. Turn Caps Lock on again. Click. It's still on because it didn't resend the Caps Lock key. See that? It's just turning it on.

And you can very easily reverse that button to turn it off if you wanted to. Make another button that says Turn Caps Lock off. You could make your own toggle button if you want to. That's kind of silly because you could just press the Caps Lock key yourself. But this way you can force the Caps Lock key to always go on instead of toggling between on and off. And that's what Nancy was missing.

Nancy, you could do the same thing with Scroll Lock. Just replace that with the Scroll Lock command.

Now, me personally, I hate Send Keys. In the extended cut for members, which Nancy, you're a member, so you can watch it, I'm going to show you how to do this without using Send Keys. I hate Send Keys. I can't stand Send Keys. I've had all kinds of problems on my databases because Send Keys is unreliable. This will work for you just fine because it sounds like you have a very simple thing going on there, but for serious databases, you don't want to use Send Keys.

It involves one more programming library that I'll have to have you copy from the website. You're a Gold member, so you can just download the template if you want to. But we can do this without Send Keys. We can actually set the keyboard state using another function. We can set Caps Lock on and off without using Send Keys. That'll be in the extended cut for the members.

Members, extended cut. I'll show you how to use a function instead of Send Keys to turn the Caps Lock, Num Lock, Scroll Lock keys on and off. We don't like Send Keys. Stop using Send Keys. I hate it. So we'll learn how to do it without Send Keys in the extended cut.

As a reminder, Silver Members and up get access to all of my extended cut videos. Gold Members get access to the complete code vault that you saw today and the download folders. You can just grab the template.

How do you become a member? Click the join button below the video. After you click the join button, you'll see a list of all the different types of membership levels that are available.

Silver Members and up will get access to all of the extended cut TechHelp videos, live video and chat sessions, and more. Gold Members get access to a download folder containing all the sample databases that I build in my TechHelp videos, plus my code vault where I keep tons of different functions that I use. Platinum Members get all the previous perks plus access to my full beginner courses and some of my expert courses.

These are the full length courses found on my website and not just for Access. I also teach Word, Excel, Visual Basic, ASP, and lots more.

These free TechHelp videos are going to keep coming as long as you keep watching them. I'll keep making more.

If you liked this video, please give me a thumbs up and feel free to post any comments that you have. I do read them all.

Make sure you subscribe to my channel, which is completely free. Click the bell icon and select all to receive notifications when new videos are posted. Click on the show more link below the video to find additional resources and links. You'll see a list of other videos, additional information related to the current topic, free lessons, and lots more.

YouTube no longer sends out email notifications when new videos are posted. If you'd like to get an email every time I post a new video, click on the link to join my mailing list.

If you have not yet tried my free Access Level 1 course, check it out now. It covers all the basics of building databases with Access. It's over three hours long. You can find it on my website or on my YouTube channel. If you like Level 1, Level 2 is just $1. It's also free for all members of my YouTube channel at any level.

Want to have your question answered in a video just like this one? Visit my TechHelp page and you can send me your question there.

Click here to watch my free Access Beginner Level 1 course, more of my TechHelp videos, or to subscribe to my channel.

Thanks for watching this video from AccessLearningZone.com.
Quiz Q1. What is the main issue Nancy is facing with the Send Keys command when using it to set Scroll Lock?
A. Send Keys only toggles Scroll Lock instead of setting it explicitly on or off
B. Send Keys does not support Scroll Lock at all
C. Send Keys requires special administrator privileges
D. Send Keys will crash Access if used with Scroll Lock

Q2. What is the purpose of the Send Keys command in Access VBA?
A. To send simulated keyboard input to the application as if typed by the user
B. To display message boxes
C. To open external programs
D. To directly modify table data

Q3. How does the Get Key State module help address Nancy's issue?
A. It allows you to read the current on/off state of special keys like Caps Lock, Num Lock, and Scroll Lock
B. It creates a custom keyboard layout
C. It disables Send Keys entirely
D. It generates reports in Access

Q4. According to the video, why does Richard dislike using Send Keys in production databases?
A. Send Keys is unreliable and can cause problems in databases
B. Send Keys is too slow for real-time applications
C. Send Keys requires a paid license from Microsoft
D. Send Keys only works with Word and Excel, not Access

Q5. What is the correct way to ensure a key (like Caps Lock) is set ON using Send Keys and the Get Key State module?
A. Check the key state with a function, and only send the key if it is currently OFF
B. Send the key command repeatedly until it is on
C. Toggle the key regardless of its current state
D. Ask the user to manually turn it on

Q6. What does the Send Keys "{CAPSLOCK}", True command do in Access VBA?
A. Toggles the state of the Caps Lock key, simulating a key press
B. Turns Caps Lock on regardless of its current state
C. Turns Caps Lock off regardless of its current state
D. Sends the string "CAPSLOCK" to the active field

Q7. What action should you take if you want a button to only turn Caps Lock OFF?
A. Use the Get Caps Lock function to check if it is ON, and only send "{CAPSLOCK}" if it currently is
B. Reboot the computer
C. Use the Send Keys command twice
D. Manually press the Caps Lock key

Q8. Which of the following is NOT a key that can be checked with the Get Key State module as shown in the video?
A. Escape key
B. Caps Lock key
C. Num Lock key
D. Scroll Lock key

Q9. Where can members access the more reliable method of setting keyboard state without using Send Keys?
A. In the extended cut for Silver and Gold members
B. In the free version of the video
C. Through Microsoft Word only
D. By emailing Nancy

Q10. If you want to use Send Keys to send the value from the First Name field to a Notes field, what is the general approach?
A. Move focus to the Notes field, then use Send Keys with the first name value as the argument
B. Type the name manually
C. Write a direct SQL update query
D. Use a Message Box to display the value

Answers: 1-A; 2-A; 3-A; 4-A; 5-A; 6-A; 7-A; 8-A; 9-A; 10-A

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 focuses on how to use VBA and the SendKeys function to control the state of the Caps Lock, Num Lock, and Scroll Lock keys in Microsoft Access. Nancy, one of my Gold members, wrote in looking for a way to reliably turn Scroll Lock on with SendKeys, rather than simply toggling it, which is what the standard SendKeys command does.

Let me explain the challenge. Nancy wants to click a button and have Scroll Lock reliably set to "on." She uses this in conjunction with a third-party application that changes her keyboard layout. The issue is that SendKeys only toggles the key's state. If Scroll Lock or Caps Lock is already on, running SendKeys will turn it off, and if it's off, it will turn it on. She needs a way for her button to make sure the key is on, regardless of its initial state.

I've been using Access for many years and, while I used SendKeys a lot in the early days, it can be unreliable. It is usually better to avoid it, but since that's what Nancy is working with, I want to get her solution working first before suggesting alternatives.

To start, you can build a button on a form in Access that uses SendKeys. For example, to send the letter "A" to a field, you can set the focus to that field and use the SendKeys command. You can also use SendKeys to send special keys like Caps Lock, Scroll Lock, or Num Lock, by putting their names in curly braces. However, as Nancy noticed, these commands only toggle the state of the key in question. There's no built-in way to check the state before toggling.

That's where a little bit of extra VBA comes into play. You need a way to detect the current status of Caps Lock, Num Lock, or Scroll Lock before deciding to send the key press. This involves some extra VBA functions that read the current keyboard state. I've created a free module in my code vault called "Get Key State." This includes functions that let you check whether each of those keys is currently on or off. There's no need to worry about how the underlying code works for now. You just need to copy it into a standard module in your Access database, and then you can use the functions GetCapsLock, GetNumLock, or GetScrollLock to read the current state of the key.

Once you have this in place, you can modify your button's code so it first checks whether, for example, Caps Lock is already on using GetCapsLock. If it's not on, then SendKeys can be used to turn it on. This way, the button only turns the key on and never off, no matter how many times you click it. You can do the same thing for Scroll Lock or Num Lock, just swap out which function and which key code you're checking and sending.

You could also create another button to always turn the key off. It's a bit redundant since you can press those keys directly on your keyboard, but it does allow you to control these keys via VBA for very specific scenarios like Nancy's workflow.

Now, although this solution works, I don't recommend SendKeys for anything other than the most basic cases. It can behave inconsistently and lead to unforeseen issues in complex databases. In the extended cut for members, I show a much better alternative using a different programming method. This alternative lets you set the keyboard state directly without using SendKeys, which is more reliable.

As a reminder, Silver Members and up get access to all of the extended cut videos where I cover more advanced or alternative techniques. Gold Members get full access to the code vault and all downloadable templates. Platinum Members receive all these perks plus free access to my complete beginner and expert courses, covering not just Access but also Word, Excel, Visual Basic, ASP, and other programs.

If you found this helpful, I always appreciate a thumbs up, and feel free to leave comments or questions. I do read them all. Make sure to subscribe to my channel, and if you want email notifications for new videos, be sure to sign up for my mailing list, as YouTube no longer sends email notifications.

If you are new to Access, take a look at my free Access Level 1 course, which covers all the basics and runs over three hours. The next level is only a dollar, or it's free with any membership level on the channel.

If you want your own question answered in a future video, you can submit it through the TechHelp page on my website.

A complete video tutorial with step-by-step instructions on everything discussed here is available on my website at the link below.

Live long and prosper, my friends.
Topic List Using SendKeys to toggle special keys in Access VBA

Programming a button to send the Scroll Lock key

Using SendKeys to target specific form fields

Sending characters and field values using SendKeys

Using curly braces for special keys in SendKeys

Demonstrating SendKeys with Caps Lock and Num Lock

Limitations of SendKeys with toggle keys

Reading the state of Caps Lock, Num Lock, and Scroll Lock

Importing a Get Key State module into Access VBA

Creating functions to check key states in VBA

Programming a button to display the state of Caps Lock

Conditional logic to turn on Caps Lock only if it is off

Using VBA code to selectively turn Caps Lock on

Adapting code for Scroll Lock and Num Lock with SendKeys
 
 
 

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: 4/30/2026 2:09:43 PM. PLT: 1s
Keywords: TechHelp Access CapsLock, Caps Lock, NumLock, Num Lock, ScrollLock, Scroll Lock, SendKeys, GetKeyState, user32, GetCapsLock, GetNumLock, GetScrollLock, keybd_event, ToggleCapsLock, ToggleNumLock, ToggleScrollLock, Toggle  PermaLink  Caps Lock On Off in Microsoft Access