[Webinar] Streamline your web hosting managementRegister Today

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

Shortcut Keys

Hi,

I am developing an Access App & I want to 'listen' for keys to open specific forms from anywhere in the app. For example  <Crtl & S> opens the suppliers form.

I am using code like:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF1 Then .....

But can't work out how to listen to key combinations such as Ctrl + S

Cheers

Doug
0
WilloWomble
Asked:
WilloWomble
  • 6
  • 4
2 Solutions
 
rockiroadsCommented:
Have you looked at creating a macro called AutoKeys? You can define shortcuts in there to open up forms, run code etc.
Do bear in mind that not all combinations are available and you run the risk of overwriting standard window shortcuts.
Have a look here at an example http://www.brainbell.com/tutorials/ms-office/Access_2003/Assigning_A_Macro_To_A_Keystroke_Combination.htm
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Here is an example:


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    
    If (Shift And acCtrlMask) > 0 Then
        If KeyCode = vbKeyR Then
            If Not SSF_IsLoaded("frmAx2") Then
                DoCmd.OpenForm "frmAx2"
            End If
            Forms!frmAx2.SetFocus
        End If
        If KeyCode = vbKeyL Then
            If Not SSF_IsLoaded("frmAx3") Then
                DoCmd.OpenForm "frmAx3"
            End If
            Forms!frmAx3.SetFocus
        End If
        If KeyCode = vbKeyB Then
            If Not SSF_IsLoaded("frmAx4") Then
                DoCmd.OpenForm "frmAx4"
            End If
            Forms!frmAx4.SetFocus
        End If
    End If
 
End Sub

Open in new window

0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
rock eee roads ... what a nice surprise!!

mx
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Here you go also:
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
   '----------------------------------------
 
    
End Sub

Open in new window

0
 
rockiroadsCommented:
Howdo MX, how ya doing!
Very brief visit. Its that time of the year when I need to get 3k points just to keep my membership alive, ha!

For specific code wise, MX version better obviously. A dirtier way is to store the last key hit. Not as elegant of course

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

    Static iLastKeyCode As Integer
   
    If iLastKeyCode = 17 And (KeyCode = Asc("S") Or KeyCode = Asc("s")) Then
        MsgBox "CTRL=S Hit"
    End If
   
    iLastKeyCode = KeyCode
End Sub

0
 
rockiroadsCommented:
I meant specific form wise, not specific code wise
doh!
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
That time of the year, huh.  Seems to be that time of the 'month' for some people I know, lol.

Also, for someone with 5.37 million pts ... how the hell could EE require you to get 3K / month to keep it status quo!!!  Just not right!

mx
0
 
rockiroadsCommented:
well its all about money I guess. Im not sure how I amassed the points this year, must be due to cleanups as I have hardly been here.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
How we doing here ?

mx
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

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