I've got an Access DB I'm reading through a Word VBA macro that contains an
image field.
I'm using bookmarks to navigate to the fields and replace the contents with
data from the database query. The text fields work great, the image field
has given me a challenge.
For the image, I am able to select the picture box and do a Selection.Paste
to paste from the clipboard. The problem is that I had to manually copy the
image to the clipboard first.
What I'd like to do is somehow get the image from the recordset field
(populated by the query) into the clipboard so it can be pasted using the
Selection.Paste function.
Maybe I'm overcomplicating this, but I can't seem to find any references to
any examples anywhere.
Any help here would be greatly appreciated.
I've attached a code snipet below.
Dennis
If regPhotoDBPath <> "" Then
Set dbPhotos = OpenDatabase(Name:=regDBPath & "\Photos.mdb")
Set rdMemberPhotos = dbSIMSPhotos.OpenRecordset("SELECT tblMemberPhoto.
CAPID, tblMemberPhoto.MemberPhoto FROM tblMemberPhoto WHERE tblMemberPhoto.
CAPID = " & CAPID & " ;")
rdMemberPhotos.MoveFirst
If (IsNull(rdMemberPhotos.RecordCount) = False) Or (rdMemberPhotos.
RecordCount > 0) Then
'------------------------------------------
' Member Photo
'------------------------------------------
If IsNull(rdMemberPhotos.Fields(1).Value) = False Then
' Get the Photo from the recordset
MemberPhoto = rdMemberPhotos.Fields(1).Value
' Move to the spot in the document where the photo will be
pasted
ActiveDocument.Bookmarks("JOINED_MM").Select
' Select the picture box
Selection.MoveRight Unit:=wdCell
' <code to copy the image to the clipboard would go here>
' Paste the image from the clipboard in the picture box (this
works if the image is already in the clipboard)
Selection.Paste
MsgBox "Paste Photo"
Else
MsgBox "Null Photo"
End If
Else
MsgBox "No Records Returned"
End If
' Close the temporary recordsets and the Access database connection
rdMemberPhotos.Close
dbSIMSPhotos.Close
End If
Cindy M -WordMVP- - 18 Jun 2005 12:53 GMT
Hi Dennis,
> What I'd like to do is somehow get the image from the recordset field
> (populated by the query) into the clipboard so it can be pasted using the
> Selection.Paste function.
You'll need to ask this in an Access (or maybe classic VB) newsgroup. It
will require either automating the Access interface (hopefully, not using
SendKeys) or using the Windows API to extract the data and convert it to the
clipboard. Or the folks there may know of some other method to do what you
need.
Certain is, though, that Word can't handle the binary data stored in the
field. It does require it to come over the Clipboard or be inserted from a
file on disk.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Dennis Van der Vieren - 18 Jun 2005 14:28 GMT
Thanks Cindy,
I was thinking that was the case with Word.
I will ask this question on a VB newsgroup as you suggest to see what
response I get there.
Thanks for the response.
Dennis