Your objective is clear enough. Unless they changed it in the newest version of Access, there is not easy way through code to do that. You can use a “paste action” on an OLE object to get text from the clipboard, but getting an image is much more complicated – which is probably why you have few responses.
I can suggest several options, which will either require some funds or some research.
Option 1: Get an image from the clipboard into your file
You can physically click on the OLE field and use then click any of the paste functions (Ctrl-V, Right-Click, Paste Button)
To use the clipboard through code, however, can be a complicated venture in VBA for anything more heavier than text. The OLE Paste method only works for text – to get the image, you’ll have to manipulate the image’s location in memory, convert it to a bitmap format and then embed the data in Access. You will have to search the web for information on using the clipboard and will need a 3rd party tool to convert the JPG to a BMP, and most of the code you find will be written in C++.
In addition to the complicated code, the OLE conversion engine for Access is terribly inefficient. To see how bad it is, create a table with an OLE field. Create a form with that field and add a few pictures by using the paste button. Watch how the size of the mdb grows much faster than the size of the images you are pasting.
Option 2: Purchase a 3rd party “plug in” that does the task for you
There are a number of them out there, and it comes down to a factor of “time versus money”. Either you spend the time researching, developing and debugging, or you spend the money on buying it ready to go.
I personally chose to not take either option (which is why I have no code to offer you).
I developed a tool that provides a button to add an image to the db using Access’s File Open dialog to select the file (in any standard image format). My module stores the image data directly in a table and recreates the file in the temp directory for viewing in an image control and printing. My module also provides the user with the ability to export the image from the db back to a file, using Access’s Save As dialog. This method produces an exactly 1 for 1 size ratio when bringing an image in and I am able to impose a file size restriction (which you can’t do with the clipboard).
My method also has the same 2 options (Time vs. Money). If you choose Option 1, start with “Storing binary data” in your search for how to do it.
Not only will your database grow quickly if you put any images into the tables, but it wil lbecome unstable and more liable to corrupt. We used to use that technique a few years ago and gave up when the database corrupted and couldn't be recovered.
I would seriously suggest that you put a link in your table to where the picture sits on the disk. That way you won't get the performance drag from having the image sitting in your database, you won't neet to use OLE (the image object will do quite well).
I did have code for putting the image into the file from the form (it grabbed the image in put it on the form and from there into the table) but frankly I'm not prepared to dig it up for what think is a futile, and unwise, approach.
I intend to use this for one single picture only, namely the logo to the company buing my application. Do you still think it’s an bad idea to import the picture into my application ?
For all othe pictures used in my application I’m using linked objects.
thanks a lot for your advice.
PS! I just found an example that perfectly well import a image to a OLE field in a table.
But now, I’m not sure if I want to use it at all :-/
"I intend to use this for one single picture only, namely the logo to the company buing my application. Do you still think it’s an bad idea to import the picture into my application ?
For all othe pictures used in my application I’m using linked objects."
No that should be fine, but I would use the image control rather than the OLE control. Putting the image in through code would simply be a case of setting the image box properties, probably in the Form OnLoad event.
Here is a Sample Access Database that can use jpeg or gif as pictures...
I hope this would help.
(Here you I've used the technique of only saving the path of the picture in the database and not the acutal picture and therefore a it is a better way to keep the size of your database under control and use jpegs and gifs in access)
Somebody had mentioned stability, corruption and keeping the size under control.
The method I am employing of storing images in the db will actually work for any file type. I am not embedding nor relying on OLE conversion. I am opening the file in binary format and storing the actual binary information that comprises the file in Long Integer format, along with it's original filename and extension as text fields.
As an added precaution, it keeps the "stored" files in a seperate BE db with the table linked to my primary BE.
I control file size on the front end - in my case, I limit the files to 256 KB as a 256 KB JPEG file has more than enough image quality for the application I'm developing.
My client has experienced zero issues with stability and corruption - after all, I'm writing 1's and 0's to the db, nothing more.
For Vestigo's single image application to store the company logo, you could either use a linked file, or to keep it fully self contained, have a seperate table with 1 OLE field and paste the image directly to that field.
On forms and reports, use an OLE control and set the field of that table as the recordsource, or if you use a linked file, use the picture control and set the path programatically.
My method would work as well, although it would be overkill for a single image.