Control Sequence from Userform Control

N

Nigel

In a userform textbox I can use ctrl+v to paste a previously copied text
item. How can I intiate this sequence or indeed any other keyboard control
or escape sequence from a control button?
TIA
 
N

Nigel

Hi All,
Discovered a method to paste as follows, however the event is triggered
twice so I paste the data twice, so my questions are

1. Why does the mousedown event run twice ?
2. If this is normal how do I handle this double event?

I need to be able to paste the contents of the clipboard into TextBox1 just
once, I could either apply extra code to prevent the double copying or clear
the clipboard after the first copy occurs - which is the better option and
how do I achieve this?

Private Sub TextBox1_MouseDown(ByVal Button As Integer _
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = 2 Then
SendKeys "^v"
End Sub
 
B

Bob Phillips

Nigel,

Double events usually happen because the action within the event causes
exactly the same event that was initially trapped, firing the event a second
time before the first finishes. With worksheet and workbook events, you turn
EnableEvents off, but this doesn't work for forms, so you need to do it
yourself.

An example for you would be

Dim fReEntry As Boolean

Private Sub TextBox1_MouseDown(ByVal Button As Integer _
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Not fReEntry Then
fReEntry = True
If Button = 2 Then SendKeys "^v"
fReEntry = False
End If
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
N

Nigel

Hi Bob
Thanks for the reply. In fact I tried a similar approach to your proposal
but as with yours the setting of the boolean to False on exit allows the
retrigger to occur again! It appears that the whole event re-runs - if I
leave the boolean as false then I cannot reapply the paste until I unload
and reload the userform.

I could use another form event to set the boolean to False, but I just seem
to be building up layers of complexity that I do not feel happy about. It
has just got to be simpler than this - hasn't it??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top