PDA

View Full Version : Capture Ctrl+V to a new record



Shaimaa T
08-11-2014, 01:57 AM
Hi all,

I want to handle the event when a user clicks Ctrl+C for a complete record in a datasheet then goes to a new record and presses Ctrl+V.

I have added the following

Private Sub Text40_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 22
MsgBox "Please copy and paste the desired values one at a time."
End Select
End Sub


12090

However, since this is for a complete selected record not for a single textbox , I do not know where to add this event (in the form as a whole it would not work , and for a single control it would work only when selecting that control).

Also, I want to be able to handle the event of right clicking via the mouse and choosing Delete Record , or paste (that is , display a message to the user that he cannot delete a record , and cannot update all records at the same time- this is because the underlying view contains multiple base tables so I wanted to pop up a user-friendly message instead of the database error message).

jonh
08-11-2014, 03:52 AM
For the the paste, maybe something like


Dim Pasted As Boolean

Private Sub Form_BeforeInsert(Cancel As Integer)
Cancel = Pasted
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Pasted = KeyCode = vbKeyV And Shift = acCtrlMask
End Sub


If you don't want them to be able to delete anything, set the 'allow deletions' property to 'no'.

Shaimaa T
08-11-2014, 04:04 AM
I want the application to wait till I press Ctrl then V before it fires the Key Down event and not as soon as I press any key . How can I handle this?

jonh
08-11-2014, 04:47 AM
I don't know what you mean. The keydown event always fires when you press any key. It's not selective.

In the code I posted above (which I just edited by the way) the keydown event isn't doing anything other than setting a variable which cancels the insertion of new records.

Shaimaa T
08-11-2014, 04:58 AM
You mean pasted is integer not boolean right?

jonh
08-11-2014, 06:25 AM
Whatever. Boolean IS an integer. 0 = false, anything else = true.

Shaimaa T
08-17-2014, 03:41 AM
If I want to check the option of right click using mouse then if I chose paste , I would display a message to the user

How can I do this(instead of disabling the context menu as a whole since other functionalities will be disabled that way)?