Log in

View Full Version : Trying to use Hotkeys to manage controls on an Access form



tfurnivall
09-05-2013, 08:38 AM
Hi!

I'm trying to find a way to use Hotkeys to manage controls on an Access form.

I have a tab (multi-page) control, and I want to be able to use Ctrl=Alt+{set of keys} to make individual pages visible or not.

So far I have enabled Key Preview for the form, and written a Keydown handler for the Form:


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

'MsgBox "Key pressed (1): Shift value is " & Format(Shift)

' Detect Hot-keys for the pages in the MultiPage wizard, and make them Visible or not visible
' P/D/X/S/R/H/C
If Shift = acAltMask + acShiftMask Then
MsgBox "Key pressed (2): Shift value is " & Format(Shift)
' Disable Key press processing for the form!
If KeyCode = vbkeyP Then ' Project Definition
' Can't be hidden!
ElseIf KeyCode = vbkeyD Then ' Source Definition
Me.pgSourceDefinition.Visible = Not Me.pgSourceDefinition.Visible
ElseIf KeyCode = vbkeyX Then ' Extract Phase
Me.pgExtract.Visible = Not Me.pgExtract.Visible
ElseIf KeyCode = vbkeyS Then ' Scoring Phase
Me.pgScoring.Visible = Not Me.pgScoring.Visible
ElseIf KeyCode = vbkeyR Then ' Review Phase
Me.pgReview.Visible = Not Me.pgReview.Visible
ElseIf KeyCode = vbkeyH Then ' Project History
Me.pgHistory.Visible = Not Me.pgHistory.Visible
ElseIf KeyCode = vbkeyC Then ' Project Configuration
Me.pgConfigure.Visible = Not Me.pgConfigure.Visible
Else
End If
Else
End If

End Sub


I can detect that a key has been pressed (the commented out msgbox (1)), but I can't seem to get to msgbox (2). I know that KeyDown is cumulative so I don't expect to get there until I have both keys down, and then I should e able to test KeyCode.

No Luck :(

Does anyone have any ideas?

Tony

PS Also cross posted to access Programmers UK site

tfurnivall
09-05-2013, 11:39 AM
Update!
Hot keys update!

I have changed the msgbox to a debug.print, and get the following:


Key pressed (1): Shift value is 2; KeyCode is 17()
Key pressed (1): Shift value is 6; KeyCode is 18()
Key pressed (1): Shift value is 6; KeyCode is 18()
Key pressed (1): Shift value is 6; KeyCode is 18()
Key pressed (1): Shift value is 6; KeyCode is 68(D)
Key pressed (1): Shift value is 6; KeyCode is 83(S)
Key pressed (1): Shift value is 6; KeyCode is 88(X)
Key pressed (1): Shift value is 6; KeyCode is 82(R)
Key pressed (1): Shift value is 6; KeyCode is 72(H)
Key pressed (1): Shift value is 6; KeyCode is 67(C)

but even though this meets the conditions for changing the visibility of the pages, nothing happens...

Code now reads:

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

Debug.Print "Key pressed (1): Shift value is " & Format(Shift) & "; KeyCode is " & KeyCode & "(" & Chr(KeyCode) & ")"

' Detect Hot-keys for the pages in the MultiPage wizard, and make them Visible or not visible
' P/D/X/S/R/H/C
If (Shift = acAltMask + acShiftMask) And KeyCode = vbkeyD Then
Me.pgSourceDefinition.Visible = Not Me.pgSourceDefinition.Visible
ElseIf (Shift = acAltMask + acShiftMask) And KeyCode = vbkeyX Then ' Extract Phase
Me.pgExtract.Visible = Not Me.pgExtract.Visible
ElseIf (Shift = acAltMask + acShiftMask) And KeyCode = vbkeyS Then ' Scoring Phase
Me.pgScoring.Visible = Not Me.pgScoring.Visible
ElseIf (Shift = acAltMask + acShiftMask) And KeyCode = vbkeyR Then ' Review Phase
Me.pgReview.Visible = Not Me.pgReview.Visible
ElseIf (Shift = acAltMask + acShiftMask) And KeyCode = vbkeyH Then ' Project History
Me.pgHistory.Visible = Not Me.pgHistory.Visible
ElseIf (Shift = acAltMask + acShiftMask) And KeyCode = vbkeyC Then ' Project Configuration
Me.pgConfigure.Visible = Not Me.pgConfigure.Visible
Else
End If

End Sub


Must be something real simple, yet real not obvious (at least to me ;-)

T

mrojas
09-11-2013, 09:06 AM
Could you share with us as to why you need to use Hot Keys to show/hide pages?

tfurnivall
09-11-2013, 10:18 AM
It's primarily for two reasons.
1) As a project progresses, the status of the project will show only the appropriate pages, but I would like to have a way to short-circuit that.
2) I try as far as possible not to make navigation a mouse-only function, so some hot-keys to move between pages quickly would be nice.

(Plus, there's always, 3) It looks like an interesting technical challenge ;-)

This is not a show-stopper, and I've more or less decided to keep the pages all visible until the project gets closer to deployment, and worry about it then. However, reason #3 keeps nagging at me...

Tony