• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

Working with the windows clipboard in VBA code

I am wanting to be able to make use of the Windows clipboard from within VBA code in an Access database.  Is this at all possible?  I have found on Chuck Pearson's website an example of how to do this with Microsoft Excel, but not Access.  I have at least a couple business applications where this would come in handy, and maybe a couple personal ones as well, in the future.  Anyway, what I want to do cannot be done with the SendKeys function, b/c that for some reason does not want to work correctly with the program I have to send the text to.

Regardless of what I find to be the best method to deal with sending text to another program, I really want to find out how to basically save the string stored in a variable to the Windows clipboard, so that it's available to paste to a separate application.  I can get the values I need into a variable, I just need to transfer from that variable to the clipboard.  It would not be much data, so it would not be an issue of having enough system memory or anything along those lines.

I've considered using the Windows API - I don't know if that's related to the clipboard, but from other things I've heard and read, it sounds like it may be what I really need.  The copy/paste deal was hopefully an inbetween until I can learn the API better.

If someone has any recommendations on the API references, and how to use with VBA, I'm all ears.  I'd like to find a good reference somewhere - I'd prefer a website, but if it means I have to buy another book, then I may can do that, as well.

Thanks for any help/info on this one!
0
john316kjv
Asked:
john316kjv
  • 5
  • 5
1 Solution
 
gecko_au2003Commented:
I found this :

'==============================

Copying Information to the Clipboard
Access forms provide end users with the ability to copy the information in a particular field to the Windows clipboard, so that it can then be pasted into another application. By selecting one or more entire records from a form or table, users can also copy and paste that information, though the format is not necessarily useful for all applications. Instead, in many applications, it's useful to copy custom text based on various fields of or more records, and Access doesn't readily supply this functionality.

The method I have used to copy custom information to the clipboard is as follows:

Create a "dummy" form for use in copy and paste operations, and put a Memo field on the form.
Use Visual Basic to gather the information needed from the record or records into a single String variable, using DAO Dataset methods, or simple Form access if only the current record's information is needed.
From Visual Basic, open the dummy form, set the Text property of the Memo field to the String variable's contents.
Use the Memo field's Copy method to copy the text to the clipboard.
 
'================================================

Which was from this site :

http://www.poplarware.com/accesstips.html#clipboard

From what you were saying though , you may have seen this already ! :

http://www.cpearson.com/excel/clipboar.htm

I will research further and post more if I find anything else
0
 
gecko_au2003Commented:
Here is some code from vba express, might be worth signing up with them and searching around on there as there are always a ton of topics that help me on there , the url below is with regards to clearing the clipboard in VBA :

http://www.vbaexpress.com/kb/getarticle.php?kb_id=205

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
john316kjvAuthor Commented:
Thanks, gecko,
  I'll take a look at this, hopefully today - or tomorrow if not.... just got really busy today, all of a sudden, so may not have time until tomorrow.

Will post back with what I find.
0
 
gecko_au2003Commented:
ok not a problem, just as long as you get your problem solved and keep myself and possibly other experts updated now and then ;)

I hope what I posted helps !

Kind regards

Gecko
0
 
john316kjvAuthor Commented:
Gecko,
   It looks like the one from here:
http://www.poplarware.com/accesstips.html#clipboard
  may do the trick.  I've not had a chance to try it yet, but it does look pheasible.  I believe I actually saw that one before, but it never stuck.  If possible, I'll try it either this week or next.  I'm going ahead and accepting that one, as it seems to be just what I need.  Besides, depending on how things go here, I may not have a chance to test it until sometime next week, or even the next.  All of a sudden, very busy this week.

Thanks.
0
 
john316kjvAuthor Commented:
Just a follow up.  I've been trying this at home with a different project (personal), and her sollution there is just not working yet.  I may just be missing a reference or something, but I can't find a copy method of the text box (which I have linked to a memo field in a table).  I'll check the other ones..
0
 
john316kjvAuthor Commented:
Well, all the others posted are for Excel, not Access, so the will not work.  The one posted for Access did not seem to work for me, but it could be that the necessary reference was not listed that was necessary for it to work... I tried to use a "copy" method of the text box, but it didn't seem to exist.  Did she mean something different by memo field?  I'll try something else... maybe need to use a recordset?
0
 
gecko_au2003Commented:
I would have to give it a go later on as I have never used VBA for trying to do this, within visual basic you do :

Clipboard.SetText ="My String" '<-- Something to that extent

I will have a go later on tonight or tommorow and I will post back with anything I find :) of use
0
 
john316kjvAuthor Commented:
Thanks!  I'll give that a go, and see if that works as well.  That would actually be MUCH better than the other whole merry go round method! :-)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now