Code Samples for Businesses, Schools & Developers

Last Updated 29 Oct 2017


If you want to prevent users copying and pasting text into an Access form:

1.   Set the form’s Key Preview property to YES
2.   Put this code in the form's KeyDown event

CODE:


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

    Dim intCtrlDown As Integer
    intCtrlDown = (Shift And acCtrlMask) > 0

    If KeyCode = vbKeyV Then
      If intCtrlDown Then
        MsgBox "You Pressed Ctl + V"
        KeyCode = 0
      End If
    End If

    If KeyCode = vbKeyC Then
      If intCtrlDown Then
        MsgBox "You Pressed Ctl + C"
        KeyCode = 0
      End If
    End If

End Sub




UPDATE 2 Feb 2022

This tip is included in my Prevent Copy & Paste in Access Forms video on YouTube.

The video demonstrates how to prevent the following methods of copying & pasting data:
1.   Using the right click context menu
2.   Using keyboard shortcuts Ctrl+C & Ctrl+V
3.   Using the ribbon
4.   Direct data entry into tables

The video is available at: https://youtu.be/Y2MHYbuWmYU or you can click on the video below

       



Colin Riddington           Mendip Data Systems                 Last Updated 29 Oct 2017

Return to Code Samples Page Return to Top