Copy to clipboard using SendKeys

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Access 2003

Trying to assemble a bunch of fields, place it in a text control, highlight
it and simulate Ctrl-C using SendKeys.

It does not work; probably because the field with the highlighted text must
loose the focus when a button is clicked to run the sendkeys code.

Tried to set focus on the field prior to running the code. That didn't work
either.

Any suggestions on how code can be executed without loosing the focus on a
field. Would a timer event do it?
 
Why do you need SendKeys? There is usually a better way to do almost anything
than by using SendKeys.

That being said, you could use:
Me.PreviousControl.SetFocus as the first command under the button.

Barry
 
I was looking for something simpler than the API methods and I did find a
suggestion to use DoCmd.RunCommand acCmdCopy but have not tried it yet.

To answer Barry's question.

It was just the first thing I thought of after some searching through other
forums. All I found at that time was the API techniques which I felt was too
long winded for a simple copy requirement.

I will try his suggestion to use PreviousControl which might function
differently than using the control name.
 
Hmm, OK you can either:-
Paste the code Stephen pointed you to into a module

Then:-
YourVariable = ' ... build up the string here
call ClipBoard_SetText(YourVariable)

.... to put the variable contents into the clipboard, or

YourVariable = ' ... build up the string here
with me.CopyFromControl
.Value = YourVariable
.SetFocus
End With
docmd.RunCommand acCmdCopy

and hope it works.
 
Thanks Terry,

Both methods work and the API method is simple with instructions on how to
use 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

Back
Top