Results 1 to 5 of 5
  1. #1
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211

    Automating Word MailMerge Won't Merge Images

    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...

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If you want to provide files for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Here is how I used to do Word mail merge (similar to your approach, first exporting data to a csv to prevent Word from interacting with Access directly):
    Code:
    Set WordApp = CreateObject("Word.Application")
             
    With WordApp
        .Application.Visible = True
        .StatusBar = "Preparing to add a new Mail-Merge document in Word format.  Please wait..."
        .Documents.Open strFileName, ReadOnly:=False, AddToRecentFiles:=False, Revert:=True
        .ActiveDocument.MailMerge.OpenDataSource Name:= _
            strMailMergeFileName, ConfirmConversions:=False, ReadOnly:= _
            False, LinkToSource:=True, Revert:=True, AddToRecentFiles:=False
        .ActiveDocument.ActiveWindow.View.ShowFieldCodes = False        
        .ActiveDocument.MailMerge.SuppressBlankLines = True         
        .ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False   
        .ActiveDocument.MailMerge.Destination = 0                   ' Merge to a New Document
    .......... 
    ..........
    ..........
    End With
    
    
    
    
    WordApp.Quit
    Set WordApp = Nothing
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks for sample code Vlad. Not sure exactly what is different in your code from mine that would prevent image from populating the field.

    I did find a work-around: Since in my document the particular field codes for the signatures are in a Word table, I wrote code so that if the field value in the data source is a path to an image file, I removed the contents of that table cell (basically only the field code), and replaced it with the image itself. Therefore there is no issue around merging the image. This wouldn't work if images needed to be dynamic, different for each merged document. In my case all documents would share the same image, so it's simpler to paste the image into the source merge document, replacing a merge field, before performing the merge.

    Thanks again for the answers...

  5. #5
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    I was going to suggest the other day that you embed the image in the source document. I've been a long time user of Albert Kallal's Super Easy WordMerge and what I've done is set it up so there is both a shared library of template documents and a personal library of template documents. If someone wants to use a signature image they can do so and save it to their personal library.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error in Access VBA Automating Word Merge from Excel
    By RMittelman in forum Programming
    Replies: 4
    Last Post: 01-20-2021, 05:56 PM
  2. word mailmerge with access/sql
    By roberto21 in forum Access
    Replies: 3
    Last Post: 10-18-2020, 09:43 AM
  3. MS Access and MS Word MailMerge
    By tgall in forum Access
    Replies: 1
    Last Post: 11-14-2015, 11:02 PM
  4. Access and Word MailMerge
    By saharmon in forum Access
    Replies: 0
    Last Post: 10-28-2014, 02:37 PM
  5. Access and mailmerge in Word
    By Popnorth in forum Access
    Replies: 2
    Last Post: 01-21-2013, 08:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums