Results 1 to 15 of 15
  1. #1
    Modify_inc is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    100

    Need to disable the Delete a Record shortcut, CTRL -

    I would like to disable the shortcut, CTRL - which allows a user to delete a record. A user accidentally deleted a record while typing in an email address that had an underscore in the email address. While trying to type it she must have hit the CTRL key instead of the Shift key follow by the -. She noticed the delete confirmation, but not thinking, pressed enter and thus confirmed the deletion of the record.



    Other than telling her to pay more attention, how can I disable the shortcut in Access 2013?

    Would using the Application.OnKey be ideal for this?

    Thanks
    Mike

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    I've never encountered this. Was not even aware of this shortcut. Review https://www.accessforums.net/forms/d...eys-41957.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Modify_inc is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    100
    Quote Originally Posted by June7 View Post
    I've never encountered this. Was not even aware of this shortcut. Review https://www.accessforums.net/forms/d...eys-41957.html
    I experimented with some of the code from the links and modified it for my needs, but I can't even get Access to completely disable the CTRL key just for testing, let along with the dash character.

    I tried this first, just to see if I could get Access to disable the CTRL key by itself, as the guy in the post said it worked for him.

    Code:
    Private Sub Form_Open(Cancel As Integer)
        If (Shift And acCtrlMask) > 0 Then
        Keycode = 0
        Shift = 0
        End If
    End Sub
    Nothing, the CTRL key still functions normally. I tried it without the Shift variable as I didn't think I needed it, but still no luck.

    Should I run it under a different procedure type other than Open?

    I tried using the Application.OnKey "^-", "" but I keep getting an error that the method or data member is not found.

    I don't understand why because that command is recommend all over the internet for redirecting the key to a blank string.

  4. #4
    trevor40's Avatar
    trevor40 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    407
    try this, i use it for my time tracking system, it disables both the alt and ctrl keys


    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim intCtrlDown As Integer, intAltDown As Integer, intShiftDown As Integer
    intAltDown = (Shift And acAltMask) > 0
    intCtrlDown = (Shift And acCtrlMask) > 0
    If intCtrlDown Then
        If KeyCode = vbKeyF4 Then
            KeyCode = 0
        Else
            Exit Sub
        End If
    End If
    If intAltDown Then
        If KeyCode = vbKeyF4 Then
            KeyCode = 0
        Else
            Exit Sub
        End If
    End If
    

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    And this is what I use for the F12 key to hide the current form and open a new form
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case vbKeyF12
                KeyCode = 0
                If lstEmp > -1 Then   'lstEmp is a list box
                    DoCmd.OpenForm "employee details", , , "end_pk = " & lstEmp.Column(1)
                    Forms!startup.Visible = False
                Else
                    MsgBox "Please select an employee"
                End If
    
        End Select
    
    End Sub
    Note that both trevor40 and I use the "Form_KeyDown" event, NOT the "Form_Open" event.

    Could also use the "Form_KeyUp" event.

  6. #6
    Modify_inc is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    100
    Quote Originally Posted by trevor40 View Post
    try this, i use it for my time tracking system, it disables both the alt and ctrl keys


    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim intCtrlDown As Integer, intAltDown As Integer, intShiftDown As Integer
    intAltDown = (Shift And acAltMask) > 0
    intCtrlDown = (Shift And acCtrlMask) > 0
    If intCtrlDown Then
        If KeyCode = vbKeyF4 Then
            KeyCode = 0
        Else
            Exit Sub
        End If
    End If
    If intAltDown Then
        If KeyCode = vbKeyF4 Then
            KeyCode = 0
        Else
            Exit Sub
        End If
    End If
    
    Thanks for the code, but I can still use the ALT and CTRL keys. It's like none of the code is even executing. I noticed the End Sub was missing in your code, but when I copy it and tested it with my form, it didn't even error out. I'm pretty sure it should have given me an error not having an End Sub, correct?

    Anyways, I added the End Sub, but still the ALT and CTRL keys still work in the form.

    Any ideas?

    Mike

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In the form that you want to limit ALT and CTL actions, did you open the form properties, click on the EVENT tab, go to the very last property and set "Keypreview" to YES?

    This is necessary because by default, the form only sees keystrokes after the controls on the form.
    You must set the "Keypreview" property on EACH form - it is not a global setting.

    As stated above, you must use the "KeyDown" or "KeyUp" events.

  8. #8
    Modify_inc is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    100
    Quote Originally Posted by ssanfu View Post
    In the form that you want to limit ALT and CTL actions, did you open the form properties, click on the EVENT tab, go to the very last property and set "Keypreview" to YES?

    This is necessary because by default, the form only sees keystrokes after the controls on the form.
    You must set the "Keypreview" property on EACH form - it is not a global setting.

    As stated above, you must use the "KeyDown" or "KeyUp" events.
    No, I had no idea I was suppose too. I have it set to Yes now.

    I only have one form, and I am using the KeyDown event for it. Unfortunately, I can still use the ALT and CTRL keys.

  9. #9
    trevor40's Avatar
    trevor40 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    407
    set break points in the code and step debug to see if it's even getting to the code and running

  10. #10
    Modify_inc is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    100
    Quote Originally Posted by trevor40 View Post
    set break points in the code and step debug to see if it's even getting to the code and running
    With the stop command between the last End If and the End Sub, I have noticed this pattern:

    If I press any keys OTHER than CTRL or ALT, it will stop.
    If I just press CTRL or ALT and no other keys, it will continue, it does not stop.
    If I press CTRL or ALT WHILE pressing any other key, it will process the shortcut normally and not stop. So if I press ctrl - it will ask to delete the record.

    I thought the code was suppose to suppress the CTRL and ALT keys. Seems to be doing the opposite, unless I'm misunderstanding something.

  11. #11
    trevor40's Avatar
    trevor40 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    407
    post your code pls.

  12. #12
    Modify_inc is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    100
    Quote Originally Posted by trevor40 View Post
    post your code pls.
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim intCtrlDown As Integer, intAltDown As Integer, intShiftDown As Integer
    intAltDown = (Shift And acAltMask) > 0
    intCtrlDown = (Shift And acCtrlMask) > 0
    If intCtrlDown Then
        If KeyCode = vbKeyF4 Then
            KeyCode = 0
        Else
            Exit Sub
        End If
    End If
    If intAltDown Then
        If KeyCode = vbKeyF4 Then
            KeyCode = 0
        Else
            Exit Sub
        End If
    End If
    Stop
    End Sub

  13. #13
    trevor40's Avatar
    trevor40 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    407
    Quote Originally Posted by Modify_inc View Post
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim intCtrlDown As Integer, intAltDown As Integer, intShiftDown As Integer
    intAltDown = (Shift And acAltMask) > 0
    intCtrlDown = (Shift And acCtrlMask) > 0
    If intCtrlDown Then
        If KeyCode = vbKeyF4 Then
            KeyCode = 0
        Else
            Exit Sub
        End If
    End If
    If intAltDown Then
        If KeyCode = vbKeyF4 Then
            KeyCode = 0
        Else
            Exit Sub
        End If
    End If
    Stop
    End Sub
    your code is only checking if F4 has been hit as well as ctrl or alt,
    adjust your code to check for the key combination you need.

  14. #14
    Modify_inc is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    100
    Quote Originally Posted by trevor40 View Post
    your code is only checking if F4 has been hit as well as ctrl or alt,
    adjust your code to check for the key combination you need.
    Ok, that made a big difference. I got it to work, but only using the CTRL and the subtract key on the numpad.

    Looking at the list of key codes from Microsoft, https://msdn.microsoft.com/en-us/lib...=vs.60%29.aspx

    There is no key code for the hyphen/dash key on the main keyboard. Only found the vbSubtract key which is code 109 and apparently only works for the subtract key on the numpad.

    Any idea what the code is for the hyphen/dash key on the main keyboard?

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Don't know if this will help but - from the ASCII table, all of these codes generate the same character in appearance:

    Chr(45)

    Chr(6)

    Chr(150)

    Chr(173)

    And Asc("-") - by typing the hyphen on the main keyboard or minus on numeric keypad - returns 45.

    Bing search: Microsoft keycode hyphen
    Apparently a common issue.
    These have some interesting comments
    http://answers.microsoft.com/en-us/o...5-c89673ad5603
    https://social.msdn.microsoft.com/Fo...silverlightnet
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-25-2014, 01:42 PM
  2. Print reports in a tab ctrl in a tab ctrl
    By marcsessoms in forum Reports
    Replies: 1
    Last Post: 02-18-2012, 12:15 AM
  3. Replies: 1
    Last Post: 11-28-2011, 04:06 PM
  4. Disable ctrl + dot(.) in access for report
    By armm1388 in forum Security
    Replies: 2
    Last Post: 06-24-2011, 06:40 PM
  5. how Disable ctrl + dot(.) in access
    By armm1388 in forum Security
    Replies: 1
    Last Post: 05-30-2011, 03:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums