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 > Shift Click > < Trap Form Errors | Bill To Ship To >
Shift Click
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   2 years ago

Shift-Click Button Action in Microsoft Access


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

In this Microsoft Access tutorial, I will show you how to configure a button to perform a different action when the Shift key is held down during a click. You'll learn to distinguish between regular and Shift-click actions using a simple VBA function, enhancing your form's functionality with minimal code changes.

Travis from Concord, California (a Platinum Member) asks: How can I make my button in Microsoft Access do something different when I hold down the Shift key while clicking it? I'm trying to set up a form where a button usually performs a basic function, but I want it to have an alternate function when the Shift key is held down during the click. I want my database users to be able to trigger different actions based on whether they click the button regularly or use the Shift key. Can you show me how to set this up so that it can distinguish between a regular click and a Shift-click? I'm not really sure where to start. Is there a way to configure this directly in Access, like maybe using an event or some kind of condition that checks if the Shift key is pressed when the button is clicked?

Members

In the extended cut, I will show you how to configure button actions for different key combinations in Microsoft Access. We will learn how to handle not just shift clicks, but also control clicks, alt clicks, and combinations like control shift click, giving you versatility in user interactions.

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

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.

KeywordsShift Click in Microsoft Access

TechHelp Access, Microsoft Access Shift-click, custom button actions Access, Access VBA toggle action, button click events Access, VBA getkeystate function, user32 keyboard state Access, alternate button function Access, VBA shift key detection, Access event programming, form functionality VBA Access

 

 

 

Comments for Shift Click
 
Age Subject From
2 yearsRight When I Need ItJeffrey Kraft
2 yearsLove ThisSandra Truax

 

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 Shift Click
Get notifications when this page is updated
 
Intro In this video, I will show you how to make a button in Microsoft Access perform a different action if you hold down the shift key while clicking it. You'll learn how to use a global module and a Windows library function to detect key presses in VBA, set up a Boolean function to check for the shift key, and integrate this logic into a form button's click event. We'll also talk about providing users with helpful control tip text, and I'll walk you through simulating print and preview actions based on regular clicks versus shift clicks.
Transcript Today, I'm going to show you how to have a button perform a different action if you hold down the shift key while you click on it. For example, you have an invoice button right here. If you click on it normally, it pulls up the print preview so you can see it. But if you hold down shift and click on it, it sends it right to the printer. That would be pretty cool.

Well, that's what we're going to do in today's video. Today's question comes from Travis in Concord, California, one of my platinum members. Travis asks, "How can I make my button in Microsoft Access do something different when I hold down the shift key while clicking it? I'm trying to set up a form where a button usually performs a basic function, but I want it to have an alternate function when the shift key is held down during the click. I want my database users to be able to trigger different actions based on whether they click the button regularly or use the shift key. Can you show me how to set this up so it can distinguish between a regular click and a shift click? I'm not really sure what to start. Is there a way to configure this directly in Access like maybe using an event or some kind of condition that checks if the shift key is pressed when the button is clicked?"

Yes, there certainly is. It's going to involve a little programming. So this is going to be a developer-level video. What does that mean? If you don't know how to program in VBA and you want to get started, go watch this video first. It's about 20 minutes long. It will teach you everything you need to know to get started. So go watch that and then come on back.

All right, so here I am in my TechHelp free template. This is a free database. You can grab a copy on my website if you want to. In here, I've got customers and customers can have orders, and in here, I've got an invoice button. Normally, when I click on this button, it takes me into the invoice report and puts it into print preview mode because I don't like wasting paper. So I don't like making my button so it sends it straight to the printer. But some of you do like that. So instead of having to open this and then click the print button, wouldn't it be nice if I could just shift click that button and have it go straight to the printer? I mean, yeah, you can make a second button, but that wastes screen real estate and, of course, real estate is expensive. We can do this with a couple of lines of code.

First, we have to either create or go into a global module out here. Now I already have one. This is my global module. It's in this template. If I open it up, you'll see this stuff. There's just some basic stuff in here like a sleep timer and some other stuff. Let's go create a new one. I'm going to go into create and then pick module, not class module, just a regular module. You get these two lines up top already set for you. We are going to put in one declaration to a Windows library function. I'm just going to copy and paste it in here for you. There it is. Pause now and go ahead and type that in, or you can screen capture it and OCR it, or if you're a gold member, you can just grab it out of the database. But that's it right there.

What does this whole thing mean? Well, you don't need to understand every single little bit of this, but basically, there's a function called get key state, and it's part of the library user 32 that comes with Windows. We're basically telling Access, "Hey, I need you to go out and use a Windows function to get the key state to get the keyboard state." So we can detect if a particular key is being pressed or held down. Every key has its own code. There's a big long list of them somewhere. Here's the only one we need for this example. There it is. We need to declare a private constant called key shift, and it's this value here. It's a hex value one zero. Again, you don't really have to worry about all the details. It's like the example that I give you. You don't have to understand all of the pieces and parts under the hood of a car to be able to drive the thing. So I'm just giving you the basics here, and then we're going to learn how to drive it in just a minute.

We've got a function that can get the keyboard state, and we know specifically what key we're looking for. Now we're going to make a little function that's simply going to return a value, true or false, if the shift key is being held down. That's going to look like this. All right? Public function. It's public, so now everybody could use it. Okay? And it's is shift key pressed, and it's going to return a Boolean value, a true/false value. That's just going to say, okay, get key state key shift. Okay? That's the key we're looking for, the key shift key. All right? If this thing returns less than zero, then that means it's true. Otherwise, it's false. This is just a fancy way of saying if get key state key shift is less than zero, then is shift key pressed equals true else is key shift equals false. It's just a fancy way of writing that's a little shortcut way. Okay?

Now we've got a little function we can actually use in our database to determine if the shift key is being held down. Okay? So copy that to your clipboard so we've got it. Now let's go over to the form we want to actually use it on. Design view here. In this invoice button, I'm going to right-click build event that brings me into the invoice button's click event. All right? We need to meet our refresh either way. Here, I'm going to say if is shift key pressed, that's the function we just created. All right? I put the little open and close parentheses after it so I know it's a function. Then what do you want to do if the shift key is down? Well, I don't actually want to send this to my printer because I don't want to waste paper while I'm teaching you guys how to waste paper. So I'll just message box sending invoice to printer like that. We'll just fake it. All right. Fake it till you make it. Otherwise, the shift key is not down, and we'll do what we were doing before, which is just opening the report in print preview mode.

Okay? So as soon as this runs, it's going to check to see if the shift key is down and then process that accordingly. All right? Let's throw in a debug compile. Make sure everything compiles. Save it. All right. We got to save our order form and our module. So I'm going to say yes. It wants us to save our module. Let's call this key press mod. Hit okay. All right. Close it. Close it. Let's go back into the order form and click on the invoice button without the key. All right. And I don't know. Normally, all right. Let's close it. Now I'm going to hold down the shift key on the keyboard, holding it down, click, and there you go. Sending the invoice to the printer. See? It ran the function to determine the shift key was down and did this accordingly.

One more thing I like to do. I like to do this. I like to say if the user hovers over that, let's give them a control tip text. It tells them what they're doing. So on the other tab under control tip text, I'm going to say click to preview invoice, shift click to send direct to printer. No one can ever remember all these little things. It's a training issue, but all right. Now if I go back in here and hover over that, there's my control tip text. See? It tells you what you need to do. There it is. That's it. It's pretty straightforward, pretty simple, huh?

Now, what about the other keys? There's control and alt as well. You can do the same trick with it. You can do shift click, control click, alt click. You can do control shift click. You can do control alt click, control alt shift click. Just don't do control alt delete. But I will show you how to do all of those in the extended cut for the members. Silver members and up get access to all of my extended cut videos. So not just this one, all of them. There's hundreds of them by now. Only worth your investment. Gold members can download the databases that I've built in these classes. And you get access to my code vault with tons of cool stuff like this. And lots more. So yeah. And if you like learning with me, I got tons of developer lessons on my website. Come check it out.

But that's going to do it for today, folks. There's your TechHelp video. I hope you learned something. Live long and prosper, my friends. I'll see you next time, and members, I'll see you in the extended cut.

TOPICS:
Detecting key press with GetKeyState
Using global modules in Access
Setting up a function for shift detection
Creating a Boolean function in VBA
Integrating shift detection with button click
Event handling with VBA in Access
Providing user feedback via control tip text
Simulating print function with message box

COMMERCIAL:
In today's video, we're going to explore how to make a button in Microsoft Access perform different actions with a simple trick. By holding down the shift key while clicking the button, you can trigger an alternate function—like sending an invoice directly to the printer. We'll guide you step-by-step through adding a small amount of VBA code to achieve this. You'll learn to integrate a global module, use a Windows library function to detect key presses, and implement a function to determine when the shift key is pressed. Plus, we'll cover how to add control tip text for user clarity. This tutorial opens up possibilities to customize actions in your Access forms using shift, control, and alt keys. You'll find the complete video on my YouTube channel and on my website at the link shown. Live long and prosper my friends.
Quiz Q1. What is the purpose of using the 'get key state' function in this tutorial?
A. To determine if the caps lock is enabled
B. To check the language settings of the keyboard
C. To detect if the shift key is being pressed or held down
D. To identify the operating system version

Q2. What is the primary action of the button when clicked without holding the shift key?
A. It opens the invoice in design view
B. It sends the invoice directly to the printer
C. It previews the invoice report
D. It deletes the invoice

Q3. What programming language is used to achieve the alternate button function?
A. Python
B. JavaScript
C. VBA (Visual Basic for Applications)
D. C++

Q4. Why is a global module used in this tutorial?
A. To store temporary user data
B. To save database backups
C. To reuse functions across different forms
D. To manage user login sessions

Q5. What kind of value does the 'is shift key pressed' function return?
A. Integer
B. String
C. Boolean
D. Array

Q6. Which of the following describes the purpose of control tip text in the tutorial?
A. It provides instructions for advanced users only
B. It shows keyboard shortcuts for system commands
C. It offers a brief description of the button's functions when users hover over it
D. It creates visual effects on the form

Q7. What are some possible benefits of using a shift click functionality instead of creating multiple buttons?
A. Reducing screen real estate and keeping the interface clean
B. Allowing multiple users to access the button simultaneously
C. Increasing the button's click speed
D. Enhancing database security

Q8. How can users adapt the tutorial's functionality for other keys, such as control or alt?
A. By using a different library other than 'user32'
B. By replacing the key shift value with the corresponding value for control or alt
C. By modifying the database structure
D. By using special hardware accessories

Answers: 1-C; 2-C; 3-C; 4-C; 5-C; 6-C; 7-A; 8-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 addresses a common request from users: how to enable a button to perform an alternate action when the shift key is held down during a click. Imagine having an invoice button. Normally, clicking it shows a print preview, but if you hold the shift key and click, it sends the document directly to the printer. This dual functionality is what we'll explore today.

This query comes from Travis in Concord, California, one of my platinum members, who wants to set up a form in Microsoft Access where a button functions differently based on shift key use. He asked if there's a straightforward way to achieve this through Access without initially knowing where to start. Well, Travis, it indeed involves a bit of programming, specifically VBA, and I'll guide you through the process.

First, I suggest that if you're new to VBA, you might want to watch a foundational video I offer that runs about 20 minutes long before continuing with this tutorial. Once you're familiar with the basics, you can delve into this more advanced technique.

Within the TechHelp free template, available on my website, I have already set up some foundational elements. Here, customers can place orders, and there's an invoice button which typically opens the print preview mode to avoid wasting paper. But what if you prefer the option to send it directly to the printer by simply shift-clicking? Instead of cluttering your interface with multiple buttons, we can achieve this functionality with some code.

You'll need to work with a global module, which either you can create, or if you have an existing one, you can add to it. I'm working with one here, containing basic essentials like a sleep timer. To start, create a regular module, not a class module, where you'll introduce a Windows library function. Specifically, we'll use the "get key state" function to determine the state of the keyboard keys. We're essentially instructing Access to utilize this Windows function to check if a key is pressed.

We will need a private constant for the shift key. It's important to understand that we don't need to know every detail here, just as you don't need to know every part of a car to drive it. This constant uses a hexadecimal value to identify the shift key.

After setting this up, we'll create a function to return a Boolean value, indicating whether the shift key is pressed. This public function can then be used throughout our database applications. If the function detects the shift key is down, it returns true.

With this function in place, it's time to apply it in the database. Navigate to the form you want to use it on, like the one with the invoice button. Access the button's click event, and incorporate the function to check for the shift key. If it is pressed, execute the desired alternate action, like sending the invoice to the printer. For demonstration purposes, I'll simulate this with a message box saying the invoice is being sent to the printer, rather than actually wasting paper.

It's a good practice to use a debug compile to ensure there are no errors before saving your work. Be sure to save any changes to your forms and modules. When revisiting the order form, test by clicking the invoice button normally, and then while holding the shift key to see the different outcomes.

Additionally, to enhance user experience, I recommend providing a control tip text. This serves as a helpful reminder by displaying text like "Click to preview invoice, shift click to send direct to printer" when users hover over the button.

While we've focused on the shift key, similar methods can be applied to other keys like control and alt, or combinations of them. For more in-depth coverage, including different key combinations, silver members can access extended cut videos, and gold members can download working databases and access the code vault.

I hope this tutorial provides valuable insight into customizing button functionalities within Microsoft Access. You can find a complete video tutorial with detailed instructions on my website. Live long and prosper, my friends.
Topic List Detecting key press with GetKeyState
Using global modules in Access
Setting up a function for shift detection
Creating a Boolean function in VBA
Integrating shift detection with button click
Event handling with VBA in Access
Providing user feedback via control tip text
Simulating print function with message 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: 4/30/2026 10:10:15 AM. PLT: 2s
Keywords: TechHelp Access, Microsoft Access Shift-click, custom button actions Access, Access VBA toggle action, button click events Access, VBA getkeystate function, user32 keyboard state Access, alternate button function Access, VBA shift key detection, Access ev  PermaLink  Shift Click in Microsoft Access