Including graphics in Access to Word merge

S

Sandy

I have a routine that creates a standard letter to a variety of people. The
routine uses a Word template that contains doc properties to receive the
content of fields such as “nameâ€, “addressâ€, “Todaydate†etc. At the end of
the routine, the fields are unlinked.

I would like to insert a signature .jpg file that would vary according to
whether I have addressed the recipient by their first name or their title and
surname. I have experimented with INSERTPICTURE, but only managed to create
an empty graphic box. Is there a work round? Help gratefully received.
 
P

Peter Jamieson

Did you double up backslashes in the pathname of the file(s) you
INCLUDEPICTURE'd ?

e.g. { INCLUDEPICTURE "c:\\mydir\\myfile.jpg" }

Peter Jamieson
 
S

Sandy

Peter/Graham

Thanks for your help. I manually inserted {IncludePicture
"C:\\FilePath\\AlanHodge.jpg"} and this signature file was inserted and
displayed in every case (which is considerable progress!), but also when I
had intended that "Alan.jpg" should be inserted. My code in Access is

If Not IsNull(strSalutation) Then
strSalutation = ctl.Column(12, varValue) 'In a multiselect box
strSig = "C:\FilePath\Alan.jpg"
Else
strSalutation = ctl.Column(6, varValue) & _
" " & ctl.Column(2, varValue) 'Title and surname
strSig = "C:\FilePath\alanhodge.jpg"
End If
....
prps.Item("Signature").Value = strSig

How can I make Access recognise the Signature doc property and insert the
correct link?

Sandy
 
P

Peter Jamieson

A possible problem wth your code is that isnull("") is False, i.e. an empty
string is not the same as a null string.

The Signature property needs to contain the pathname with doubled-up
backslashes

The Includepicture field needs to be like

{ INCLUDEPICTURE "{ DOCPROPERTY Signature }" }

where both pairs of {} are the sort you can insert using ctrl-F9, not the
ordinary ones on the keyboard

You will /may/ need to set

myWordApplication.Options.UpdateFieldsAtPrint = True

and/or

myWordApplication.Options.UpdateLinksAtPrint = True

(I've never quite worked out which)

and if you are outputting to a new document, you may /also/ need to select
the document and re-execute all the INCLUDEPICTURE field codes (or all the
field codes, whichever is the simpler)

Peter Jamieson
 
S

Sandy

Thanks very much for your help. I tried every combination I could think of
with INCLUDEPICTURE, even putting the field into the access table and linking
the word file, without success.

In the end I've added this code to the access subroutine and it works!

With Selection.Find
.Text = "Mr A Hodge"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.MoveUp Unit:=wdLine, Count:=2
If fDear Then 'Address by first name
Selection.InlineShapes.AddPicture FileName:= _
strDocsPath & "alan.jpg" _
, LinkToFile:=False, SaveWithDocument:=True
Else
Selection.InlineShapes.AddPicture FileName:= _
strDocsPath & "alanhodge.jpg" _
, LinkToFile:=False, SaveWithDocument:=True
End If
 

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