Solved

MS Access - Capture pressed key onclick

Posted on 2016-10-05
4
46 Views
Last Modified: 2016-10-05
I have a form with a button.  When I click the button I need to be able to tell if CRTL was pressed at the time the button was clicked.
I'm trying to add this hidden feature where holding down CRTL and clicking a button does something different than just clicking the button.

Is there a way to do that?
0
Comment
Question by:keschuster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 250 total points
ID: 41829833
Use the mousedown event
Private Sub Command2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Shift And acCtrlMask) Then
    MsgBox "CTRL key down and button clicked", vbInformation
Else
    MsgBox "You clicked just the button", vbInformation
End If
End Sub

Open in new window


acShiftMask The bit mask for the SHIFT key.
acCtrlMask The bit mask for the CTRL key.
acAltMask The bit mask for the ALT key.
1
 
LVL 34

Assisted Solution

by:ste5an
ste5an earned 250 total points
ID: 41829841
Use the MouseDown or MouseUp event of the button. You can determine whether shift, alt or ctrl was pressed by evaluating the Shift parameter:

Private Sub btnYourButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

  Dim CtrlOnlyPressed As Boolean
  
  CtrlOnlyPressed = (Shift And acCtrlMask = acCtrlMask)

End Sub

Open in new window

0
 

Author Closing Comment

by:keschuster
ID: 41829864
thanks guys
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 41829870
Just wondering what assistance can give a comment substantially identical than the above .
Anyway glad to have helped you
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question