Inserting OLE Bitmap into Word document

G

Guest

Hi all

I’m writing a routine which opens a new Word document and sticks content
from the current record into it. I want to put an OLE Bitmap from the current
record into the Word document. I am having trouble doing this. I have thought
of three possible ways to do this. Please advise me on them!

Word’s ActiveDocument.Shapes.AddPicture method requires a filename. Is there
a filename associated with an OLE field in Access, and can I get to it?

Alternatively, Word provides a method to paste the contents of the clipboard
into the document. Does Access provide any means to copy a field value onto
the clipboard?

Lastly, I could use a field in the table to store the filename of the bitmap
instead of storing it as OLE (enabling me to use Word's AddPicture method).
If I did this, is there a way I could get Access to display the picture
itself when the record is viewed, rather than just the filename?

Thanks again

David
 
S

Stephen Lebans

David have you worked through your issues yet?

--

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

Guest

Hi Stephen. Thanks for asking.

I'm come to the conclusion that it is not possible to use VB to insert the
contents of an OLE field into a Word document. However, it is possible to
change the field to contain a pathname for the object, and use this pathname
to place the object into a Word document.

Cheers

David
 
S

Stephen Lebans

I'm just heading out the door to work but it certainly is possible. As
you mentioned, the Clipboard route is probably the simplest solution.
You can programmatically copy the contents of the OLE field to the
Clipboard, setfocus to the Word App, Paste the current contents of the
Clipboard, continue to loop through your records.

Alternatively, you can export the contents of the OLE field to a disk
based Jpeg file and then insert the Jpegs into the Word doc. The
solution can be code to work at runtime as requried or export the entire
table at once.

--

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

Guest

I never found a way to programmatically copy field values from Access onto
the clipboard.

I solved this problem by ditching OLE fields altogether, and using a text
field to store the path of the image instead. I worked out how to get Access
to show the image in a form, even though it was only storing the path. The
path could then be used as an argument for Word's AddPicture method. I'm
quite happy with this solution.

One thing that would make all this better is if I could provide the user
with a dialogue box which they can use to point Access to the filename of the
picture, instead of them having to type a filename in. Do you know of any way
I can get Access to prompt the user for a filename using a standard Windows
file dialogue?

Thanks

David
 
S

Stephen Lebans

The OLE Frame control has an Action method that allows you to ask it to
copy its contents to the Clipboard.

Your current course of action is the suggested method for displaying
Images. A method to call the standard WIndows File Dialog is here:
http://www.mvps.org/access/api/api0001.htm

It looks complicated but the code is well tested.

--

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

Guest

That's extremely helpful Stephen, thank you.

Stephen Lebans said:
The OLE Frame control has an Action method that allows you to ask it to
copy its contents to the Clipboard.

Your current course of action is the suggested method for displaying
Images. A method to call the standard WIndows File Dialog is here:
http://www.mvps.org/access/api/api0001.htm

It looks complicated but the code is well tested.

--

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

Guest

Hi Stephen

I'm playing with that code you pointed me to but I'm having difficulties
with it.

Access is telling me it doesn't recognise the variable type tagOPENFILENAME,
an instance of which is created by the function ahtCommonFileOpenSave. Is
there a class declaration somewhere I need, or do I need to add a reference
to some library or other?

Also, will this code be portable across different versions of Windows?

Thanks again

David
 
S

Stephen Lebans

Yes the code is portable across all versions of Windows.

The structure declaration for tagOPENFILENAME is the very first entry in
the souirce code on that Web page. You must copy ALL of the source code
to a new standard Code module that you create in your MDB. Make sure the
name you give to this standard Code module is not the same as any of the
function names contained in the source code.

So you copy and paste everything starting from the very top here:

'***************** Code Start **************
'This code was originally written by Ken Getz.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is

--

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

Guest

Ah, okay, I wasn't putting the code into a new module.

That's great Stephen, thanks once again!

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top