Capture Ctrl+V to a new record

The approach of sending a message after capturing Ctrl+V has a problem:

I want it to not paste only if the whole record is selected , but to paste in a control(single field) is actually needed.
 
Something like

Code:
Dim Pasted As Boolean

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

Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
If (the count of active controls are more than one) Then [I][COLOR="SeaGreen"]<--what VBA code?[/COLOR][/I]
    Cancel = Pasted
If Cancel = True Then
MsgBox "Please paste one field at a time"
End If
End If
 
I initialized a control

Dim ctrl as Control

then added
If (ctrl.ItemsSelected.Count > 1) Then

But the control need to be initialized and I guess there is still something missing.

Any help please?
 
I don't have time to look into this right now but what you can do for now is:

1. set a boolean variable to False in the Got Focus event of each control
2. set the variable to True in the Lost Focus event of each control
3. test against the variable in the Form's KeyDown event and if it's True run the code, otherwise it shouldn't run.
 
You mean when the variable is true, then the control is not focused ?

But i want when one control is focused to actually paste data , also when several are selected but not when ALL the record is selected.

There could be another way which is to allow paste normally and issue a data duplicacy error , but currently once pasted the system displays an "update error as modification affects multiple base tables"
 
I am not able to make it .

I made the boolean isFocused variable equals True in all GotFocus of controls , and false in the Lost Focus events respectively

Then I compared against Pasted in Keydown event which was Pasted = KeyCode = vbKeyV And Shift = acCtrlMask

If (IsFocused <> Pasted) Then
MsgBox "Cannot insert data for the whole record"

I don't seem to get it right.
Besides, I am missing something. IsFocused will always be true when any control is in focus even if 1 right?

Can you help please?
 
Or I can trap the error in the OnError event handler . Related to View is not updateable because the modification affects multiple base tables
 
It's a very simple task really. All you need to do is follow each step one-by-one.
I don't have time to look into this right now but what you can do for now is:

1. set a boolean variable to False in the Got Focus event of each control
2. set the variable to True in the Lost Focus event of each control
3. test against the variable in the Form's KeyDown event and if it's True run the code, otherwise it shouldn't run.

1.
Code:
Option Compare Database
Option Explicit

Private isField As Boolean
2.
Code:
Got Focus:
isField = True

Lost Focus:
isField = False
3.
Code:
Key Down event:
If Not isField Then
    [COLOR="Blue"]... put the code here ...[/COLOR]
End If
 
You are right. I just misread 3 as test against "the variable in the form keydown event " which is the Pasted variable.

If Not isfield is equivalent to If isfield=false which means lost focus in the key down event but actually we want to display the message if it is in focus and not only that - if ALL the controls are in focus.

So in this case, if only one of the controls is in got focus , it will be set to true and this is not enough to put the code(display the message).
 
If Not isfield is equivalent to If isfield=false which means lost focus in the key down event but actually we want to display the message if it is in focus and not only that - if ALL the controls are in focus.
Please test the code before you make conclusions.
 

Users who are viewing this thread

Back
Top Bottom