Code to Copy Fields to Clipboard

M

Mr. JYC

Hello,

Could someone tell me if there is code to copy data from form fields to the
clipboard?
 
D

Danny J. Lesandrini

I might be wrong about my approach, but I wrestled with this about 3 years ago,
and below is what I came up with.

I use the DoCmd.RunCommand acCmdCopy command, but only AFTER I've
placed all the text I want to show in a hidden text box. I have to toggle it visible,
load it with the address text, run the acCmdCopy command and then hide it again.

I also, in the code below, load the text into a label that is briefly made visible. This
is a que to the user that the copy is in progress, or actually, already finished.



Private Sub cmdMailLabel_Click()
On Error GoTo Err_Handler

Dim strOut As String

strOut = Me!txtSiteName & vbCrLf & _
Me!txtMailingAddress & vbCrLf & _
(Me!txtMailingAddress2 + vbCrLf) & _
Me!txtMailingCity & ", " & Me!txtMailingState & " " & Me!txtMailingZip & vbCrLf

DoCmd.Echo False
Me!txtCopyOfAddress.Visible = True
Me!txtCopyOfAddress.SetFocus
Me!txtCopyOfAddress = strOut
DoCmd.RunCommand acCmdCopy
Me!cmdMailLabel.SetFocus
Me!txtCopyOfAddress.Visible = False
DoCmd.Echo True

Me!lblMailLabel.Caption = "Address copied to clipboard." & vbCrLf & vbCrLf & strOut
Me.TimerInterval = 1500
Me!lblMailLabel.Visible = True

Exit_Here:
Exit Sub
Err_Handler:
Resume Exit_Here
End Sub
 
M

Mr. JYC

Thank you for your answers!

I just realized after looking at your code that there is a bigger problem.

The issue is that two applications have to interchange information.
Specifically, the code in Access would copy text from a field on an Access
form and then paste it to a field in a form in Word and then go back to the
Access form and copy the remaining text from the other fields to be pasted
into the Word form.

The solution that you provided is good for one field but how is
intereactivity achieved?
 
P

Paul Shapiro

Instead of copy/paste, use Word automation. You create the Word application
object in your Access code, and then use Word VBA commands to run Word.
Something like (but syntax is not correct):

Set wordApp = GetApplication("MSWord")
Set wordDoc = wordApp.documents.add(strFullPathAndFileNameOfDocumentToOpen)
wordDoc.content.range.insertAfter(strFirstField)
wordDoc.content.range.insertAfter(strSecondField)
etc.
 

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