Copy - Paste

Is there a way to single-click a text box on a form, have the contents of that textbox copied to the clipboard (in the background), and then be able to [Right-Click]-[Paste] it into another textbox?
SteveL13Asked:
Who is Participating?
 
Gustav BrockConnect With a Mentor CIOCommented:
Gustav, I put this code in the onclick event of the textbox.  
When I single click it the text does not get copied to the clipboard.

That's because when clicking you are resetting a select.
You must select something to copy. If that is the content of the textbox, modify your code to select the content, then copy:

Private Sub Felt1_Click()
    
    Me!Felt1.SelStart = 0
    Me!Felt1.SelLength = Len(Me!Felt1.Text)
    DoCmd.RunCommand acCmdCopy

End Sub

Open in new window

0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The simplest way is to use keyboard shortcuts:

Ctrl+C will copy it

Ctlr + V will paste it

If you want to use code you could, but you aren't going to really save any keystrokes or mouseclicks.
0
 
Bill PrewCommented:
For people that are comfortable with the Windows GUI standards, it doesn't seem like it would be intuitive that if they just click on a text box the content would go to the clipboard.  You could create a custom trigger on the field to trap for mouse clicks and place something in the clipboard, but it feels less than obvious, and you would have to worry about "dirty" content in the field, meaning they typed something, but haven't left the field, so it isn't in the .Value of that control yet.  Etc...

If you really need this on just a few fields, I'd probably put a small button just to the right of the text field, with an icon of label that indicates "copy".  Then if they click that button, just take the value of the text field and place it in the clipboard.  Feels more user friendly, IMHO.


»bp
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
SteveL13Author Commented:
The field I want to copy would be locked so it could not be edited.  But I do want to single click it to copy the contents to the clipboard and then [Right-Click]-[Paste] it to another unlocked textbox.
0
 
Bill PrewCommented:
As long as the control is LOCKED=TRUE and not ENABLED=FALSE, then something like this should get you started.

I haven't figured out how to stop the normal even handler from firing after this trigger runs, working on that...

Private Sub Text0_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Button = 2 Then
        With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
            If IsNull(Text0.Value) Then
                .SetText ""
                .PutInClipboard
            Else
                .SetText Text0.Value
                .PutInClipboard
            End If
        End With
    End If

End Sub

Open in new window


»bp
0
 
Bill PrewCommented:
Okay, looks like we can do it this way (Up event rather than Down).

Private Sub Text0_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Button = 2 Then
        With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
            If IsNull(Text0.Value) Then
                .SetText ""
                .PutInClipboard
            Else
                .SetText Text0.Value
                .PutInClipboard
            End If
        End With
        DoCmd.CancelEvent
    End If

End Sub

Open in new window


»bp
0
 
Gustav BrockCIOCommented:
You may be able to use the simple commands:

' Copy selected text or object.
DoCmd.RunCommand acCmdCopy
' Paste a copied text or object.
DoCmd.RunCommand acCmdPaste

Open in new window

0
 
SteveL13Author Commented:
Bill:  This does not work:

Private Sub txtDescription_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Button = 2 Then
        With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
            If IsNull(txtDescription.Value) Then
                .SetText ""
                .PutInClipboard
            Else
                .SetText txtDescription.Value
                .PutInClipboard
            End If
        End With
        DoCmd.CancelEvent
    End If

End Sub

Open in new window

0
 
Bill PrewCommented:
What versions of Windows and Access are you running, and which are 32 bit versus 64 bit?


»bp
0
 
Bill PrewCommented:
And what does "this does not work" mean?  Did you get an error?  Or did it run and nothing showed in clipboard?  Or other?


»bp
0
 
SteveL13Author Commented:
Windows 10.  Access 365.  

Ran it.  Got no error.  But got nothing in the clipboard.
0
 
Gustav BrockCIOCommented:
Well, use my simple commands. That works right away.
0
 
Bill PrewCommented:
So this should handle the copy part of things, try it there.

As far as the past goes, how would that logic work?  On this first text box, right click always copies?  But on one other specific text box right click always pastes?

Private Sub Text0_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Button = 2 Then
        If Not IsNull(Text0.Value) Then
            DoCmd.RunCommand acCmdCopy
        End If
        DoCmd.CancelEvent
    End If

End Sub

Open in new window


»bp
0
 
Bill PrewConnect With a Mentor Commented:
If you always want to paste into a second control on right click, then try:

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Button = 2 Then
        DoCmd.RunCommand acCmdPaste
        DoCmd.CancelEvent
    End If

End Sub

Open in new window


»bp
0
 
SteveL13Author Commented:
Gustav, I put this code in the onclick event of the textbox.  When I single click it the text does not get copied to the clipboard.

Bill.  This doesn't put anything on the clipboard either.  No error.  Nothing.

    If Button = 2 Then
        If Not IsNull(txtDescription.Value) Then
            DoCmd.RunCommand acCmdCopy
        End If
        DoCmd.CancelEvent
    End If

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.