So I'm trying to automate a Word mailmerge from Access. My code exports the desired record to a CSV file, then uses that file for the data source of a Word merge document.
Here is a snippet of the data source (I've trimmed out identifiable information and shortened the actual file contents)
Code:
"Heading","Address","City","State","Zip","Salutation","Paragraph1","Closing","Sig1","Sig1Type"
"Mr. and Mrs. John Doe","123 Main St.","Anytown","CA","99999","Dear John & Jane","Thank you for your donation.","Very Gratefully,"C:\\FTT\\Signatures\\Paula.png",1
The "Sig1" field is designed to be either a name (which will be printed in a script font) or the path to a signature image. If the "Sig1Type" field is 0, it's a signature. if it's 1, it's the path to a signature image.
Here is the merge field in the Word document:
Code:
{ if { MERGEFIELD Sig1Type } = 1 { INCLUDEPICTURE "{ MERGEFIELD Sig1 }" \d} { MERGEFIELD Sig1 } }
Here is my VBA code
Code:
With WordDoc.MailMerge
.OpenDataSource Name:=m_DataFile, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:="", _
Revert:=False, Format:=0, Connection:="", SQLStatement:=sql, SQLStatement1:="" ', SubType:=wdMergeSubTypeWord2000
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
.DataSource.FirstRecord = 1
.Execute Pause:=False
End With
If Sig1 = "Paula" and Sig1Type is 0, it works as expected. If Sig1 is a file path and Sig1Type is 1, like the data above, nothing shows up in that field.
HOWEVER, If I open the merge document in Word, choose the "Mailings" tab and set the data source to the CSV file above, it works fine in both cases (signature or path to file) when I preview the merge in Word.
So something must be wrong with the VBA code above, right? It's been working just fine before my customer had the bright idea to use a signature image instead of a stylized signature text, such as "Paula".
Any ideas what's going wrong here? Thanks...