Solved

microsoft vba code to be able to use a key combination from the keyboard to set a value on a form

Posted on 2012-03-22
4
735 Views
Last Modified: 2012-03-22
Hi:

On the KeyDown event, I want my Access form to see that the user has pressed the Shit and Ctrl and Alt and F5 keys simultaneously.  If this has occurred then

me.CompletionDate = Null

No idea how to use or call the custom key combination to set this value.
0
Comment
Question by:sxxgupta
  • 3
4 Comments
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 37754762
Here are the 7 combinations of the Shift argument ... from which you can trap any combination of Shift, Control and Alt ... in either the Form_KeyDown and Form_KeyUp events.  

Also ... be SURE you have Key Preview set to Yes on the Event property sheet for the form.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   
   'Shift Argument for the 7 combinations of Shift, Ctrl and Alt keys:
   '0 None
   '1 Shift Key
   '2 Ctrl Key
   '3 Shift + Ctrl Keys
   '4 Alt Key
   '5 Shift + Alt Keys
   '6 Ctrl + Alt Keys
   '7 Shift + Ctrl + Alt Keys
   '----------------------------------------
   
   'Obviously, the use of the word 'Shift' was NOT the best choice.  

End Sub

Obviously .. .'Shift' is a misleading argument name!

mx
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 37754783
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If Shift = 7 AND KeyCode = vbKeyF5 then
    Keycode = 0
    me.CompletionDate = Null
End If

End Sub

mx
0
 

Author Closing Comment

by:sxxgupta
ID: 37754870
Thanks MX
0
 
LVL 75
ID: 37754886
You are welcome ..

mx
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now