shortcut keys not working when in subform

Dear experts -
I have a main form with 2 subforms. When I'm in the main subform (which occupies most of the screen) I want to access the accelerator/shortcut keys on the parent form, which have hotkeys assigned to them. (e.g. alt-g).
These keys work fine when you are not in the subform, but not when you're on a record in the subform.
Any idea how to fix?
Thanks!
terpsichoreAsked:
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.

Gustav BrockCIOCommented:
You may try setting KeyPreview of the main form:

Private Sub Form_Load()
    Me.KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF2
            ' Process F2 key events.
        Case vbKeyF3
            ' Process F3 key events.
        Case vbKeyF4
            ' Process F4 key events.
        Case Else
    End Select
End Sub

Look up the on-line help.

/gustav
0
terpsichoreAuthor Commented:
can i do that with an alt-key combination?
0
Gustav BrockCIOCommented:
Perhaps. I've never had the need to test it.

/gustav
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

terpsichoreAuthor Commented:
hmm - it doesn't work for some reason. I put in the code and then tried to trap for it, but it would fire when i'm in the subform...
0
Gustav BrockCIOCommented:
Too bad.
I have no more ideas.

/gustav
0
terpsichoreAuthor Commented:
thanks in any case. I tried creating a button in the subform (which I maybe can make invisible) with the same accelerator key - but for some reason it doesn't fire consistently....
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
What version of Access are you runing?

This is how I get around this situation which I use ALL the time, especially when if I (sorta) run out of shortcut key letters.  I create my own shortcuts key combinations, using various combinations of Shit, Control & Alt ... usually Control+Shift+<SomeLetter>.
Noting that all of my more recent apps at 100% keyboard driven, for any essential areas users might need to 'jump' to.

Here is an example of code in a subform in another subform (two levesl) - to allow the user to jump around to any other relevant location - SF to MF, SF to another SF, MF to SF and so on. Be SURE - as Gustav noted - you have the Key Preview set to Yes on all Forms (and Sub forms). Note examples to jump two levels up.

=====
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
   '----------------------------------------
   
    If Shift = 4 And KeyCode = vbKeyReturn Then 'trap Alt+Enter which opens Form property sheet
        KeyCode = 0
        Exit Sub
    End If
   
    With Me
        If (Shift = 3 And KeyCode = vbKeyA) Then
            On Error Resume Next 'covers case where control is disabled
            .Parent.Parent.SetFocus
            .Parent.Parent.Form.txtSA.SetFocus
            Err.Clear
            Exit Sub
        End If
       
        If Shift = 3 And KeyCode = vbKeyS Then
            On Error Resume Next 'covers case where control is disabled
            KeyCode = 0
            .Parent.Parent.SetFocus
            .Parent.Parent.fsubAcctSts.SetFocus
            .Parent.Parent.fsubAcctSts.Form.txtDtRvwd.SetFocus
            Err.Clear
            Exit Sub
        End If
   
        If (Shift = 3 And KeyCode = vbKeyF) Then
            On Error Resume Next 'covers case where control is disabled
            .Parent.SetFocus
            .Parent.Form.txtFind.SetFocus
            Err.Clear
            Exit Sub
        End If
   
        If Shift = 7 And KeyCode = vbKeyX Then
            If .Parent.Parent.Dirty = True Then
                MsgBox "Please Save or Cancel the current edits before attempting to close this form.", 16, "Close Account Form"
                Exit Sub
            End If
            DoCmd.Close acForm, .Parent.Parent.Name
            Exit Sub
        End If
       
        If Shift = 4 And KeyCode = vbKeyM Then
            Call Me.Parent.mMinMax(sOp:="Toggle")
            Exit Sub
        End If
    End With
   
Form_KeyDown_Exit:
   
    Err.Clear
End Sub
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
terpsichoreAuthor Commented:
First - many thanks - very thorough.
I'm using Access 2010 - reading online, I have found that this is a known bug! key combination in a subform trying to control a hotkey in a TABBED CONTROL in a parent level does not work, apparently - Microsoft apparently has this as a known bug!

In any case, in your example, if I want this to work in a subform and execute an afterupdate event in the tab control of the parent, at which level would I put this code?

(90% of the time, the user is in the main subform)

THANKS!
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Yes ... I posted (actually confirmed) the bug to Microsoft via the MVP channel. It's all related to the Ribbon paradigm.  It will not be fixed, sadly. MANY people have encountered this bug.

Any control (especially a button) on a Tab control will have this issue.

Well, I guess you would put it in the KeyDown of the subform.
0
terpsichoreAuthor Commented:
thanks - I'll consider this 'resolved' - I will get rid of the tab control and just use regular buttons, that may do the trick... Thanks again!
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
As a result of this but, I had to write a LOT of unnecessary code to trap the existing ALT+<SomeKey> ... annoying ....

mx
0
terpsichoreAuthor Commented:
I am finding the same problem with a regular button on the parent, not just a tab control! Any ideas?
0
terpsichoreAuthor Commented:
It was a bizarre solution! The parent form has multiple pages. The button with the hotkey was on the page - I moved it to the header (seen on ALL pages) and put in code to make the button invisible when you are not on the relevant page. NOW the hotkey fires dependably. Very strange!
0
terpsichoreAuthor Commented:
see note at bottom - but this was also very helpful.
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.