KeyDown Event

B

BobV

Using a form's KeyDown event, I know that I can trap the Alt+F key down
event. But I would like to make the File menu drop down when this key
combination is pressed simultaneously. What is the VBA statement that will
make the File menu drop down when the Alt+F key combination is press
simultaneously?

The reason I am asking this is because I am using the KeyDown event to trap
certain Alt key combinations, and what happens now when the user tries to
use the Alt key to access the menu items (File, Options, Help) is that they
must first press the Alt key then press the F, O, or H key to get the menus
to drop down. I would like to allow the user to press the simultaneous key
combinations (like Alt+F, Alt+O, Alt+H) and have the appropriate menu drop
down.

Thank you,
BobV
 
G

Guest

I was having the same problem with a form in which I had some buttons mapped to (non-conflicting) alt-keys, but then the menus (custom in this case) would not respond to their alt key mappings, except as you describe in your second paragraph. The best solution I could devise was this. I have several forms that may be at issue. In each form, I placed the following code on the form's keydown event (and set the keypreview property to true):

If (Shift And acAltMask) > 0 Then Call globalAltHandler(KeyCode) 'if the alt key is down, then goto the procedure

In a module, I placed the following code:

Sub globalAltHandler(KeyCode As Integer)
Dim ctl As Object 'I chose to use late-binding and not reference the Office library: less overhead
Select Case KeyCode
Case vbKeyF
Set ctl = Application.CommandBars.Item("{menu name}").Controls.Item("&File")
ctl.SetFocus
Case vbKeyE
Set ctl = Application.CommandBars.Item("{menu name}").Controls.Item("&Edit")
ctl.SetFocus
Case vbKeyO
Set ctl = Application.CommandBars.Item("{menu name}").Controls.Item("T&ools")
ctl.SetFocus
Case vbKeyH
Set ctl = Application.CommandBars.Item("{menu name}").Controls.Item("&Help")
ctl.SetFocus
Case Else
End Select
Set ctl = Nothing
End Sub

Hope this helps!

- Scott



----- BobV wrote: -----

Using a form's KeyDown event, I know that I can trap the Alt+F key down
event. But I would like to make the File menu drop down when this key
combination is pressed simultaneously. What is the VBA statement that will
make the File menu drop down when the Alt+F key combination is press
simultaneously?

The reason I am asking this is because I am using the KeyDown event to trap
certain Alt key combinations, and what happens now when the user tries to
use the Alt key to access the menu items (File, Options, Help) is that they
must first press the Alt key then press the F, O, or H key to get the menus
to drop down. I would like to allow the user to press the simultaneous key
combinations (like Alt+F, Alt+O, Alt+H) and have the appropriate menu drop
down.

Thank you,
BobV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top