Results 1 to 3 of 3
  1. #1
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150

    Disabling Delete Key


    Hi


    i have created a deleted button in my system. but when i open a table and select a record and press the delete key on the keyboard it deletes the record from the table. How can i disable the delete key from deleting records from a table (not in a form).

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Keys are disabled by resetting the value to nothing in the form

    1. Set Key Preview = Yes in the form property sheet
    2. Add this code to the Form_KeyDown event

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    
        If KeyCode = vbKeyDelete Then
            'Del pressed - don't allow it
            KeyCode = 0
            MsgBox "The Del key has been disabled. Please use the Delete button instead"        
        End If
    
    End Sub
    I've added a message otherwise users who use Del may click it repeatedly trying to get a response
    Most other keys can be disabled in a similar way though Ctrl, Shift, Alt require slightly different code
    AFAIK the Windows key cannot be disabled

    NOTE: This code will not block key combinations e.g. Ctrl+Alt+Del. To do so requires changes to the registry
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I don't disable delete key but handle this with form BeforeDeleteConfirm event. Users get educated and eventually won't use Delete key (or ctrl+alt+del) for this situation, if they ever did either. Doubt my users would.

    Code:
    Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
    'suppress default Delete Confirm dialog box.
    Response = acDataErrContinue
    'cancel the automatic delete operation
    Cancel = True
    MsgBox "Must click Remove Test button to delete test from sample." & vbCrLf & _
            "If sample is in closed accounting period, Delete/Remove test not permitted.", , "Delete"
    End Sub
    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. Disabling Options
    By Eranka in forum Access
    Replies: 3
    Last Post: 01-23-2018, 06:18 AM
  2. Disabling Fields
    By dolovenature in forum Programming
    Replies: 2
    Last Post: 09-16-2012, 07:45 PM
  3. Disabling fields
    By bursteffect in forum Access
    Replies: 1
    Last Post: 08-30-2012, 12:54 PM
  4. Disabling fields
    By jle0003 in forum Access
    Replies: 4
    Last Post: 06-06-2012, 09:39 AM
  5. Replies: 2
    Last Post: 01-24-2012, 02:16 PM

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