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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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 PrewCommented:
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
Gustav BrockCIOCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.