Link to home
Start Free TrialLog in
Avatar of WilloWomble
WilloWombleFlag for Australia

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rock eee roads ... what a nice surprise!!

mx
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

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

I meant specific form wise, not specific code wise
doh!
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
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.