Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 821
  • Last Modified:

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

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
sxxgupta
Asked:
sxxgupta
  • 3
2 Solutions
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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
 
sxxguptaAuthor Commented:
Thanks MX
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You are welcome ..

mx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now