Hoe alle shortcuts blokkeren op een access formulier?

Status
Niet open voor verdere reacties.

Technologywatch

Nieuwe gebruiker
Lid geworden
9 okt 2019
Berichten
4
Weet iemand hoe je op een eenvoudige wijze alle shortcuts op een access formulier kan blokkeren?

Voor excel heb ik volgende oplossing op internet gevonden. Graag zou ik een gelijkaardige oplossing voor access hebben.

Code:
Sub Disable_Keys()
    Dim StartKeyCombination As Variant
    Dim KeysArray As Variant
    Dim Key As Variant
    Dim I As Long

    On Error Resume Next

    'Shift key = "+"  (plus sign)
    'Ctrl key = "^"   (caret)
    'Alt key = "%"    (percent sign
    'We fill the array with this keys and the key combinations
    'Shift-Ctrl, Shift- Alt, Ctrl-Alt, Shift-Ctrl-Alt

    For Each StartKeyCombination In Array("+", "^", "%", "+^", "+%", "^%", "+^%")

        KeysArray = Array("{BS}", "{BREAK}", "{CAPSLOCK}", "{CLEAR}", "{DEL}", _
                    "{DOWN}", "{END}", "{ENTER}", "~", "{ESC}", "{HELP}", "{HOME}", _
                    "{INSERT}", "{LEFT}", "{NUMLOCK}", "{PGDN}", "{PGUP}", _
                    "{RETURN}", "{RIGHT}", "{SCROLLLOCK}", "{TAB}", "{UP}")

        'Disable the StartKeyCombination key(s) with every key in the KeysArray
        For Each Key In KeysArray
            Application.OnKey StartKeyCombination & Key, ""
        Next Key

        'Disable the StartKeyCombination key(s) with every other key
        For I = 0 To 255
            Application.OnKey StartKeyCombination & Chr$(I), ""
        Next I

        'Disable the F1 - F15 keys in combination with the Shift, Ctrl or Alt key
        For I = 1 To 15
            Application.OnKey StartKeyCombination & "{F" & I & "}", ""
        Next I

    Next StartKeyCombination


    'Disable the F1 - F15 keys
    For I = 1 To 15
        Application.OnKey "{F" & I & "}", ""
    Next I

    'Disable the PGDN and PGUP keys
    Application.OnKey "{PGDN}", ""
    Application.OnKey "{PGUP}", ""
End Sub



Sub Enable_Keys()
    Dim StartKeyCombination As Variant
    Dim KeysArray As Variant
    Dim Key As Variant
    Dim I As Long

    On Error Resume Next

    'Shift key = "+"  (plus sign)
    'Ctrl key = "^"   (caret)
    'Alt key = "%"    (percent sign
    'We fill the array with this keys and the key combinations
    'Shift-Ctrl, Shift- Alt, Ctrl-Alt, Shift-Ctrl-Alt

    For Each StartKeyCombination In Array("+", "^", "%", "+^", "+%", "^%", "+^%")

        KeysArray = Array("{BS}", "{BREAK}", "{CAPSLOCK}", "{CLEAR}", "{DEL}", _
                    "{DOWN}", "{END}", "{ENTER}", "~", "{ESC}", "{HELP}", "{HOME}", _
                    "{INSERT}", "{LEFT}", "{NUMLOCK}", "{PGDN}", "{PGUP}", _
                    "{RETURN}", "{RIGHT}", "{SCROLLLOCK}", "{TAB}", "{UP}")

        'Enable the StartKeyCombination key(s) with every key in the KeysArray
        For Each Key In KeysArray
            Application.OnKey StartKeyCombination & Key
        Next Key

        'Enable the StartKeyCombination key(s) with every other key
        For I = 0 To 255
            Application.OnKey StartKeyCombination & Chr$(I)
        Next I

        'Enable the F1 - F15 keys in combination with the Shift, Ctrl or Alt key
        For I = 1 To 15
            Application.OnKey StartKeyCombination & "{F" & I & "}"
        Next I

    Next StartKeyCombination


    'Enable the F1 - F15 keys
    For I = 1 To 15
        Application.OnKey "{F" & I & "}"
    Next I

    'Enable the PGDN and PGUP keys
    Application.OnKey "{PGDN}"
    Application.OnKey "{PGUP}"
End Sub
 
Laatst bewerkt:
Begin eens met je code in de CODE tags te zetten :). Daarnaast vind ik niet dat je de gebruikers moet beperken in hun dagelijkse werkzaamheden; dat is ordinair pesten in mijn optiek. Als je wilt voorkomen dat ze bepaalde handelingen kunnen uitvoeren, zoals in tabellen grasduinen of het Navigatiepaneel openen, dan zijn daar veel betere opties voor.
 
Hier is de oplossing die ik samen met een collega heb uitgedokterd:

Code:
Private Sub Form_Open(Cancel As Integer)
Me.KeyPreview = True                        'turn keypreview on in order to receive all keyboard events
End Sub

Private Sub Form_KeyDown(keycode As Integer, shift As Integer)
sb_disablekeys keycode, shift
End Sub

 

Public Sub sb_disablekeys(keycode As Integer, shift As Integer)
    'All keyboard events with CTRL don’t function anymore with the exception of CTRL+C and CTRL+V
    ‘All keyboard events with ALT don’t function anymorge
    ‘All function keys are disabled
 
    Select Case shift
        Case acCtrlMask     ‘CTRL pressed
            Select Case keycode
                Case 0 To 16, 18 To 66, 68 To 85, 87 To 255
                'All keycodes with the exception of 17 (CTRL), 67 (CTRL+C) and 86 (CTRL+V) are set to 0.
                    keycode = 0
            End Select
        Case acAltMask      'Alt pressed
                    keycode = 0
    End Select

    Select Case keycode
        Case vbKeyF1 To vbKeyF16                ‘Function key pressed
            keycode = 0
    End Select
End Sub
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan