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
WilloWombleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
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 Access MVP)Database Architect / Systems AnalystCommented:
rock eee roads ... what a nice surprise!!

mx
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
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 Access MVP)Database Architect / Systems AnalystCommented:
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 Access MVP)Database Architect / Systems AnalystCommented:
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
How we doing here ?

mx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.