opening a form with a hotkey

here's the senario: I have form1 and from form1 I need the hotkey CTL+ALT+F to open form2.  The hot key must work no matter what control if any is selected on form1.

Thanks
laurau7
laurau7Asked:
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.

credoCommented:
To open form2 when any control, on form1, may have the focus you will need to create a procedure that is called from each of the controls KeyDown Event that then evaluates what keys are currently depressed.  I have fully tested and supplied the associated code below:

**ADD THE FOLLOWING CODE TO FORM1 IN
**THE GENERAL DECLARATIONS SECTION

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

    'TEST IF CTL+ALT+F ARE ALL DEPRESSED
    If Shift = (vbCtrlMask + vbAltMask) And KeyCode = vbKeyF Then
        'IF TRUE OPEN FORM2
        Form2.Show
    End If
   
End Sub

**NOW ALL YOU NEED TO DO IS ADD THE
**FOLLOWING CODE TO FORM1 AND ALL
**OTHER CONTROLS KeyDown EVENT.

call KeyEvaluate(KeyCode, Shift)

**FOR EXAMPLE IF YOU HAD A FORM WITH
**ONE COMMAND BUTTON THE CODE WOULD BE

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

    Call KeyEvaluate(KeyCode, Shift)

End Sub


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

    Call KeyEvaluate(KeyCode, Shift)
   
End Sub

'************************************

Hope this helps.
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
mcriderCommented:
Set the KeyPreview property of Form1 to TRUE, then in the form1

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   If KeyCode = 70 And Shift = 6 Then Form2.Show
End Sub


Cheers!
0
mcriderCommented:
credo,

You DONT have to test the keyevent in every control...


Cheers!
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!

credoCommented:
mcrider,

Correct.
Thanks for that.

Credo
0
laurau7Author Commented:
Thanks mcrider & credo, it works great!
0
mcriderCommented:
laurau7,

Did you use credo's code or my code?  If you used my code, credo got all the points, and I got nothing...


0
laurau7Author Commented:
Your right, I'm sorry.
I've posted a question for you.

Thanks
laurau7
0
credoCommented:
mcrider,

How do I give the point to you?

Credo
0
mcriderCommented:
Credo,  You can't... They've already been assigned to you...

This has happened to me so many times...

Oh well...

laurau7, thanks for posting a question for me!

Cheers!

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
Visual Basic Classic

From novice to tech pro — start learning today.