Keyboard shortcuts in Access 2007

Hi Everyone,

I want to create two keyboard shortcuts in Access 2007.

If one keyboard combination is pressed, the word  "Unique"  is input into a column value.

If another keyboard combination is pressed, the word "Duplicate" in input into a column value.

This is fairly easy in Excel, I am hoping to do the same in Access. I would just record the action in a macro. But it appears that access has predefined actions for Macros.

Thanks,

John
jonsuns7Asked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
For you two cases:

Private Sub txtBox_KeyDown(KeyCode As Integer, Shift As Integer)

   
    If Shift = 4 Then
        If KeyCode = vbKeyU Then Me.txtBox = "Unique": Exit Sub
    End If
   
    If Shift = 4 Then
        If KeyCode = vbKeyD Then Me.txtBox = "Dupicate": Exit Sub
    End If
   
End Sub


mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Here is the general idea ...

Private Sub txtBox_KeyDown(KeyCode As Integer, Shift As Integer)

   '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.

   '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
   '----------------------------------------
   
    If Shift = 4 Then
        If KeyCode = vbKeyU Then Me.txtBox = "Unique"
    End If
       
End Sub

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
So ... in the example above ...

Alt+U will enter Unique in the text box,
Alt+D will enter Duplicate in the text box.

You can actually many different shortcuts using a combination of Alt, Shift & Control ... simply by changing the Shift number in the If/Then statements.

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.