By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,583 Members | 617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,583 IT Pros & Developers. It's quick & easy.

Copying txtbox contents to the clipboard

P: n/a
I have an Access97 application whose form contains many text boxes.
What do I have to do in order to copy the contents of one of these text
boxes to the clipboard? I want to do this so I can then paste from the
clipboard to Word, Notepad, etc.

I know about the SetClipboardData function, but I really can't figure
out how it works. It's supposed to be used in conjunction with the
OpenClipboard function, I think.

If anybody knows, please let me know. Please be as specific as possible
in your answer, giving code samples.

Thank You.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
I have yet to see any situations where what you describe would be necessary to
do under code control (though code examples to exist). Is there some reason
the user cannot simply select the text in the control and copy it? If the
control is not editable, simply make it Locked to prevent editing, and
perhaps, make it Tab Stop = No, so the user can only select it using the
mouse, and not be confused by having it in the tab order.

Here's a link to a code example if you truly do have a need for it:
http://www.mvps.org/access/api/api0049.htm

On 31 Dec 2003 06:19:41 GMT, DataBard007 <an*******@devdex.com> wrote:
I have an Access97 application whose form contains many text boxes.
What do I have to do in order to copy the contents of one of these text
boxes to the clipboard? I want to do this so I can then paste from the
clipboard to Word, Notepad, etc.

I know about the SetClipboardData function, but I really can't figure
out how it works. It's supposed to be used in conjunction with the
OpenClipboard function, I think.

If anybody knows, please let me know. Please be as specific as possible
in your answer, giving code samples.

Thank You.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #2

P: n/a
To copy the contents of just one control (such as "Surname") use:
Me.Surname.SetFocus
RunCommand acCmdCopy

If you want something more powerful, see:
http://www.mvps.org/access/api/api0049.htm

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"DataBard007" <an*******@devdex.com> wrote in message
news:3f*********************@news.frii.net...
I have an Access97 application whose form contains many text boxes.
What do I have to do in order to copy the contents of one of these text
boxes to the clipboard? I want to do this so I can then paste from the
clipboard to Word, Notepad, etc.

I know about the SetClipboardData function, but I really can't figure
out how it works. It's supposed to be used in conjunction with the
OpenClipboard function, I think.

If anybody knows, please let me know. Please be as specific as possible
in your answer, giving code samples.

Nov 12 '05 #3

P: n/a
Mr. Jorgensen:

I want to be able to copy to the clipboard simply by clicking on the
txtbox, rather than having to select the whole item, and press ctrl + c.
It's a matter of simplicity for the user, that's all.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

P: n/a
Allen wrote:

To copy the contents of just one control (such as "Surname") use:
Me.Surname.SetFocus
RunCommand acCmdCopy
Thanks Allen, but I'm getting the following error when I use your code
in the Click event of one of the text boxes:

Runtime Error 2046
The Command or Action copy isn't available now.
You may be in a read only database or an unconverted database from an
earlier version of the application.
The type of object the application applies to isn't currently selected
or isn't in the active view.
Use only those commands and macro actions that are currently available
for this database.

It is neither a RO database nor an unconverted database. So I don't
understand. Please give me some ideas.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5

P: n/a
On 31 Dec 2003 07:39:40 GMT, DataBard007 <an*******@devdex.com> wrote:
Mr. Jorgensen:

I want to be able to copy to the clipboard simply by clicking on the
txtbox, rather than having to select the whole item, and press ctrl + c.
It's a matter of simplicity for the user, that's all.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


IMO, it's inconsiderate to the user to make it so easy to accidentally
overwrite the existing contents of the clipboard. I do see, however, how it
might be nice to have a small button next to the control to copy to the
clipboard.

Based on your reply to Allan, it sounds as if the problem is that no text is
selected in the control when you are trying to copy it. This is normal when
you click into a control with the mouse rather than navigating to it using the
keyboard, the carat is placed at the point where yu click, and no text is
highlighted.

You could use code to select all the the text in the control before you try to
copy it to the clipboard, but I think using the button as I suggest would also
solve the problem quite simply. When the user clicks the button, set the
focus to the text control, and then copy the text. The text in the control
will have been selected following the .SetFocus event.
Nov 12 '05 #6

P: n/a
Allen:

I know what's wrong now. I thought I could just click in the text box
and using a Click event procedure, get the contents of the box to copy
to the clipboard. But that doesn't work. You actually have to select
the contents with the mouse first. But I don't want to have to do that.
I want a simple click event to do all the work. Will the code sample
you referred me to allow me to do that? Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #7

P: n/a
Mr. Jorgensen:

I don't quite understand the code in the reference that you gave me. He
uses 11 api functions and 3 functions of his own design.

Do you think you could give me a brief, step by step explanation of what
each line is doing? I know that's a lot to explain, but I need to
understand it if I'm to implement it myself.

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #8

P: n/a
Well, it sounds like it should be possible to make Allen's solution work for
you, so try doing battle with that first, and we'll battle with the API code
if necessary. I think you just probably need to make sure the text in the
control is highlighted before trying to copy it.

On 31 Dec 2003 08:09:47 GMT, DataBard007 <an*******@devdex.com> wrote:
Mr. Jorgensen:

I don't quite understand the code in the reference that you gave me. He
uses 11 api functions and 3 functions of his own design.

Do you think you could give me a brief, step by step explanation of what
each line is doing? I know that's a lot to explain, but I need to
understand it if I'm to implement it myself.

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #9

P: n/a
Check the SelStart and SelLength properties of the textbox. These will let
you select the text in the textbox, then do the copy.

Example:
Me.Surname.SetFocus
Me.Surname.SelStart = 0
Me.Surname.SelLength = Len(Me.Surname.Text)
RunCommand acCmdCopy

--
Wayne Morgan
Microsoft Access MVP
"DataBard007" <an*******@devdex.com> wrote in message
news:3f*********************@news.frii.net...
Allen:

I know what's wrong now. I thought I could just click in the text box
and using a Click event procedure, get the contents of the box to copy
to the clipboard. But that doesn't work. You actually have to select
the contents with the mouse first. But I don't want to have to do that.
I want a simple click event to do all the work. Will the code sample
you referred me to allow me to do that? Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #10

P: n/a
no****@nospam.nospam (Steve Jorgensen) wrote in
<fb********************************@4ax.com>:
On 31 Dec 2003 07:39:40 GMT, DataBard007 <an*******@devdex.com>
wrote:
I want to be able to copy to the clipboard simply by clicking on
the txtbox, rather than having to select the whole item, and
press ctrl + c. It's a matter of simplicity for the user, that's
all.


IMO, it's inconsiderate to the user to make it so easy to
accidentally overwrite the existing contents of the clipboard. I
do see, however, how it might be nice to have a small button next
to the control to copy to the clipboard.


This sounds like a case for a right-click menu to me. On the other
hand, a command button might make it more obvious to users that the
functionality exists.

However, you could use a single right-click menu for all controls,
but you'd need a button for each control, which would get messy
very quickly.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #11

P: n/a
On Wed, 31 Dec 2003 20:26:03 GMT, dX********@bway.net.invalid (David W.
Fenton) wrote:
no****@nospam.nospam (Steve Jorgensen) wrote in
<fb********************************@4ax.com>:
On 31 Dec 2003 07:39:40 GMT, DataBard007 <an*******@devdex.com>
wrote:
I want to be able to copy to the clipboard simply by clicking on
the txtbox, rather than having to select the whole item, and
press ctrl + c. It's a matter of simplicity for the user, that's
all.


IMO, it's inconsiderate to the user to make it so easy to
accidentally overwrite the existing contents of the clipboard. I
do see, however, how it might be nice to have a small button next
to the control to copy to the clipboard.


This sounds like a case for a right-click menu to me. On the other
hand, a command button might make it more obvious to users that the
functionality exists.

However, you could use a single right-click menu for all controls,
but you'd need a button for each control, which would get messy
very quickly.


My logic for suggesting the button is that the desire seemed to be for a
one-click solution. Personally, I'm not sure why copying needs to be quite
that simple, but if it does, the button's a good option.
Nov 12 '05 #12

P: n/a
Mr. Jorgensen wrote:

"IMO, it's inconsiderate to the user to make it so easy to accidentally
overwrite the existing contents of the clipboard. I do see, however, how
it might be nice to have a small button next to the control to copy to
the clipboard."

I solved the problem you referred to, but without using another control.
I simply used the control's DblClick event procedure, rather than Click.
That's much less likely to accidentally overwrite the clipboard.

Also, I used the code with the api functions to do the copying and it
worked well for me.

Thanks for the suggestions.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #13

P: n/a
Wayne Morgan wrote:

"Example:
Me.Surname.SetFocus
Me.Surname.SelStart = 0
Me.Surname.SelLength = Len(Me.Surname.Text)
RunCommand acCmdCopy"

Thanks Wayne. That's good, but is there a way to modify your code so
that you can select text from 2 text boxes, concatenate them and then
send it to the clipboard?

Thanks You.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #14

P: n/a
Great - I'm glad we were able to help you through this one.

On 01 Jan 2004 03:29:38 GMT, DataBard007 <an*******@devdex.com> wrote:
Mr. Jorgensen wrote:

"IMO, it's inconsiderate to the user to make it so easy to accidentally
overwrite the existing contents of the clipboard. I do see, however, how
it might be nice to have a small button next to the control to copy to
the clipboard."

I solved the problem you referred to, but without using another control.
I simply used the control's DblClick event procedure, rather than Click.
That's much less likely to accidentally overwrite the clipboard.

Also, I used the code with the api functions to do the copying and it
worked well for me.

Thanks for the suggestions.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #15

P: n/a
Yes, but it will require more coding to do the copy work yourself. You may
be able to do this with a hidden textbox though and still use the same code.

The textbox couldn't be hidden the normal way, you would have to set it
coloring to match that of the background or shrink it down to where it was
decernable, because you can't set focus to a textbox that has its visible
property set to no. You would then concatenate the values of the other
textboxes into this one followed by selecting this textbox's contents as
done before.

To work with the clipboard yourself, check the code here.
http://www.mvps.org/access/api/api0049.htm

--
Wayne Morgan
MS Access MVP
"DataBard007" <an*******@devdex.com> wrote in message
news:3f*********************@news.frii.net...
Wayne Morgan wrote:

"Example:
Me.Surname.SetFocus
Me.Surname.SelStart = 0
Me.Surname.SelLength = Len(Me.Surname.Text)
RunCommand acCmdCopy"

Thanks Wayne. That's good, but is there a way to modify your code so
that you can select text from 2 text boxes, concatenate them and then
send it to the clipboard?

Thanks You.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #16

P: 1
Absolutely brilliant in it's simplicity. Thank you... the crutch of API is thwarted!

-LF

Check the SelStart and SelLength properties of the textbox. These will let
you select the text in the textbox, then do the copy.

Example:
Me.Surname.SetFocus
Me.Surname.SelStart = 0
Me.Surname.SelLength = Len(Me.Surname.Text)
RunCommand acCmdCopy

--
Wayne Morgan
Microsoft Access MVP


"DataBard007" <anonymous@devdex.com> wrote in message
news:3ff281f0$0$201$75868355@news.frii.net...[color=blue]
> Allen:
>
> I know what's wrong now. I thought I could just click in the text box
> and using a Click event procedure, get the contents of the box to copy
> to the clipboard. But that doesn't work. You actually have to select
> the contents with the mouse first. But I don't want to have to do that.
> I want a simple click event to do all the work. Will the code sample
> you referred me to allow me to do that? Thanks.
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]
May 2 '06 #17

This discussion thread is closed

Replies have been disabled for this discussion.