DennisOJensen
Registered User.
- Local time
- Today, 17:18
- Joined
- Jun 28, 2015
- Messages
- 62
I am trying to prevent any foolish behavior from taking place upon a form. I have textboxes and comboboxes that users need to input data into or make selections within.
I came up with a method to prevent Paste as follows:
Now while this does not actually prevent pasting it does prevent anything from being pasted which functionally is sufficient. Further I do not need to prevent them from performing a Copy but if there is a more elegant way to do this and affect all 3 functionalities that would be fantastic
Note I want to prevent both {Ctrl}-X as well as the Right-Click-Mouse-Cut Event
I have tried doing it within the Keydown event but that does not prevent keyboard Cut/Copy/Paste because the initial Keydown for {Ctrl} cannot be disabled if it is held down and then the subsequent Keydown for X, C, or V is not prevented and I cannot debug it to see what is taking place due to Focus issues. The following is what I had in my Keydown event to try and prevent Cut/Paste but it does not work.
Note: The above kind of works if I do the following as a form of debugging:
However if I remove the MsgBox logic then the Cut is not prevented.
Any help on this issue would be greatly appreciated and/or I hope what I have presented might help someone else at least with preventing pasting. Note you need to include the Declares for those api functions if you use them.
I came up with a method to prevent Paste as follows:
Code:
Private Sub ComboBox_KeyDown(KeyCode As Integer, Shift As Integer)
Call PurgeClipBoard()
End Sub
Public Sub PurgeClipBoard()
If apiOpenClipboard(0&) <> 0 Then
Call apiEmptyClipboard()
Call apiCloseClipboard()
End If
End Sub
Now while this does not actually prevent pasting it does prevent anything from being pasted which functionally is sufficient. Further I do not need to prevent them from performing a Copy but if there is a more elegant way to do this and affect all 3 functionalities that would be fantastic
Note I want to prevent both {Ctrl}-X as well as the Right-Click-Mouse-Cut Event
I have tried doing it within the Keydown event but that does not prevent keyboard Cut/Copy/Paste because the initial Keydown for {Ctrl} cannot be disabled if it is held down and then the subsequent Keydown for X, C, or V is not prevented and I cannot debug it to see what is taking place due to Focus issues. The following is what I had in my Keydown event to try and prevent Cut/Paste but it does not work.
Code:
Private Sub ComboBox_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = acCtrlMask And (Keycode = vbKeyX or Keycode = vbKeyV) Then
Shift = 0
KeyCode = vbNull
End If
End Sub
Note: The above kind of works if I do the following as a form of debugging:
Code:
Private Sub ComboBox_KeyDown(KeyCode As Integer, Shift As Integer)
Call PurgeClipBoard()
If Shift = acCtrlMask Then
If KeyCode = vbKeyC Then
Call MsgBox("Copy Text")
ElseIf KeyCode = vbKeyV Then
Call MsgBox("Paste Text")
ElseIf KeyCode = vbKeyX Then
Call MsgBox("Cut Text")
End If
End If
If KeyCode <> 9 Then 'Allow Tab
KeyCode = vbNull
End If
End Sub
However if I remove the MsgBox logic then the Cut is not prevented.
Any help on this issue would be greatly appreciated and/or I hope what I have presented might help someone else at least with preventing pasting. Note you need to include the Declares for those api functions if you use them.