• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

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
0
laurau7
Asked:
laurau7
  • 4
  • 3
  • 2
1 Solution
 
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
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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