How do i detect Copy/Paste record event?

martinr

Registered User.
Local time
Tomorrow, 04:43
Joined
Nov 16, 2011
Messages
74
I applied the code to a form save record changes to an audit table.
The update log code works Ok - but it crashes if i try to add a new record by copying and pasting an existing record...so i need to somehow detect
when a new record is being added and temporarily disable the code, then
reactivate it once the record has been added...
Two steps are:
How do i capture the copy/paste command (as keyboard strokes or mouse selection) to trigger the event and;
How do i temporarily disable/bypass some code when the Add record event is detected???
 
you can use code in the textbox OR Form KeyDown event to detect an attempt to use CTRL + V CTRL + C

Code:
Private Sub TextBox_KeyDown(KeyCode As Integer, Shift As Integer)
    If (Shift And 2) And (KeyCode = Asc("C")) Then
        KeyCode = 0
        MsgBox "Copying is not permitted"
    ElseIf (Shift And 2) And (KeyCode = Asc("V")) Then
        KeyCode = 0
        MsgBox "Pasting is not permitted"
    End If
End Sub

You can disable the right click shortcut menu to remove the option of right click>>Paste by setting FORMS>>OTHER>>SHORTCUT MENU to No.

As to bypassing the code you could declare a Public Variable (EG blnPaste As Boolean). When the user uses paste, set this to TRUE. Then at the start of your Add Record code, check if blnPaste is true and exit the code. You would need to include code to reset the global variable to FALSE also. It all depends on how your code is triggered.
 
Thanks Isskint, i'll try your suggestion...btw, Do you know if there is a way to detect the right-click>>Copy event?
 
I do not think you can detect what option is clicked in a standard right click menu. The only thing you can do is prevent it from being used by setting the ShortCut Menu option to No.

I suppose you could rewrite/recreate the right click Shortcut Menu and then allow/disallow depending on the situation.
 

Users who are viewing this thread

Back
Top Bottom