Copy / Paste

S

Steven

I want to copy the value from a textbox and paste it to another object. I
dont want to put the copy / paste on a menu bar or shortcut menu and dont
want to use Ctrl-C and Ctrl-V. What I want is to do it with a line of code.
I thought something like DoCmd.Object.Copy and DoCmd.Object.Paste but I have
looked for and tried everything. What is the code for this?

Thank you for your help.

Steven
 
S

Steven

No, not where you say something like Me.Object1 = Me.Object2.

What I am really looking for is how do you SendKey {Ctr+C} and SendKey
{Ctr+V} in a line of code so you do not actually have to hit the keys. Note:
I do not want to use a menu bar or shortcut menu.

Thanks,

Steven
 
F

fredg

No, not where you say something like Me.Object1 = Me.Object2.

What I am really looking for is how do you SendKey {Ctr+C} and SendKey
{Ctr+V} in a line of code so you do not actually have to hit the keys. Note:
I do not want to use a menu bar or shortcut menu.

Thanks,

Steven

You still haven't said exactly what you are trying to do, so here is
some generic code to copy and paste in 2 different forms.

[SomeField].SetFocus
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm "FormName"
forms!FormName.ControlName.SetFocus
DoCmd.RunCommand acCmdPaste


You could also simply write
DoCmd.OpenForm "FormName"
forms!FormName!ControlName = Me![ControlName]
but then you don't want to do that, do you?
 
S

Stephen Lebans

With the current focus in the control whose contents you wish to copy to
the Clipboard:
DoCmd.RunCommand acCmdCopy


With the current focus in the control whose contents you wish to replace
with the contents of the Clipboard:
DoCmd.RunCommand acCmdPaste

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
S

Steven

Thats It! Thank you. I thought I had tried that but I guess not. Thank you
for your help.
 
W

Wolfgang Kais

Hello Steven.

Steven said:
I want to copy the value from a textbox and paste it to another object.
I dont want to put the copy / paste on a menu bar or shortcut menu
and dont want to use Ctrl-C and Ctrl-V. What I want is to do it with
a line of code. I thought something like DoCmd.Object.Copy and
DoCmd.Object.Paste but I have looked for and tried everything.

How about AnohterObject.Value = aTextbox.Value ?
 
T

ThomasAJ

Those APIs were just what I was looking for thanks.

Do you know of a way to 'accumulate' text on the clipboard.

The 'ClipBoard_SetData' function uses an 'EmptyClipboard()' function just
before writing data to the clipboard. I tried to conditionally skip this but
NOTHING NEW was then written to the clipboard.

I want to read say 100 records and write a field's data to the clipboard:

..movefirst
do while.....
ClipBoard_SetData(!Field1 & vbCrLf)

..movenext
loop

so that I end up in the Clipboard with:
data1
data2
data3
etc
 
J

John Nurick

Hi,

What you want is possible but involves either getting deeper into the
clipboard API functions or retrieving the clipboard contents,
concatenating the new value, and putting the result back on the
clipboard.

Instead, I'd start by concatenating all the values into a string and
then putting the result on the clipboard:

Dim strBuf As String

Do Until .EOF
strBuf = strBuf & .Fields(0).Value & vbCrLf
.MoveNext
Loop
Clipboard_SetData strBuf
 
T

ThomasAJ

Yes, done that after I submitted post, thanks.

Works very well with surprisingly voluminous text.

Rhetorical question, sort of.
I wonder what the limit is?

Quite high I presume as the cliboard can hold massive objects in their
entirety.
 
J

John Nurick

Rhetorical question, sort of.
I wonder what the limit is?

Megabytes rather than kilobytes, AFAIK.
Quite high I presume as the cliboard can hold massive objects in their
entirety.

The clipboard doesn't normally hold massive objects in their entirety,
merely the information needed to make the "copying" application hand
over the data to the "pasting" application when you click Paste. That's
why you get messages about clearing the clipboard when you quit an
application after copying anything big: it's because if you want the
data available after quitting it will then actually have to be put on
the clipboard. It would be reasonable for the limit to be a substantial
percentage of the available virtual memory.
 
Top