473,385 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Copying txtbox contents to the clipboard

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
16 12422
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Carl | last post by:
I'm trying to select, with the mouse, a cell within a flexgrid that I've created, and copying the contents of that cell to the clipboard. I've tried using the Mousecol and Mouserow properties to...
2
by: Gey-Hong Gweon | last post by:
Is there a way to copy a PIL image to windows clipboard (as a dib image or a bitmap, I suppose)? What I would like to accomplish is to do a fast copy and paste of images from my python...
0
by: Ata | last post by:
Hello, I am trying to copy the contents of the output of SQL Reporting Services to a PowerPoint slide. For this, I am using SQL Reporting Services to obtain an IMAGE stream, which I paste to the...
1
by: John | last post by:
Hi How can I copy some fields to clipboard so they can be pasted into other applications? Thanks Regards
8
by: John Smith | last post by:
Hi folks, I know how to place text into the user's clipboard: Clipboard.SetDataObject("My Copied Text"); but how do I place a file in there? So, if I have a file C:\test.txt, how can I place...
9
by: Christian Blackburn | last post by:
Hi Gang, I don't know what to make of all of this, but I'm having nothing, but trouble copying data to the clipboard which should be the easiest thing in the world. The only systems I can get...
2
by: Just Me | last post by:
Dim iData As IDataObject = Clipboard.GetDataObject() Dim img As System.Drawing.Bitmap img = img.FromFile(ofd.FileName, True) Clipboard.SetDataObject(img) TextControl1.Paste() img.Dispose() : img...
19
by: Jeff | last post by:
....working with visualweb.net 2005 and vb. ....trying to simply copy the contents from a textbox to the clipboard. I've looked at a large number of places on line and they give me various...
0
by: MathewJose | last post by:
Hi, I have a DatagridView in windows form.It has got a column which has some names that are populated from master table in database.Now i need to copy a set of data against these names. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.