Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    240

    Unanswered: Help with Mail Merge

    Hi

    I've set up a script behind a command button to generate a mailmerged document, which retrieves some information from a table. This is working fine.

    But how would I go about adding additional sections onto the mail merge using an input control on the form?

    This is the code I'm using for the Mail Merge:

    Code:
    Dim objWordApp As Word.Application
    Dim objWord As Word.Document
    Dim oSel As Word.Selection
    Set objWordApp = CreateObject("Word.Application")
    Set objWord = objWordApp.Documents.Add
    
    'Make Word visible.
    objWord.Application.Visible = True
    
    objWord.MailMerge.OpenDataSource _
    Name:="O:\MIS\Employer Engagement\RECEPE_Client.mde", _
    LinkToSource:=True, _
    Connection:="TABLE dbo_tblEmployer", _
    SQLStatement:="Select * from [dbo_tblEmployer]"
    'Add Fields
    With objWord.MailMerge.Fields
        Set oSel = objWord.Application.Selection
        
        .Add oSel.Range, "Emp_Name"
        oSel.TypeParagraph
        .Add oSel.Range, "Addr1"
        oSel.TypeParagraph
        .Add oSel.Range, "Addr2"
        oSel.TypeParagraph
        .Add oSel.Range, "Addr3"
        oSel.TypeParagraph
        .Add oSel.Range, "Addr4"
        oSel.TypeParagraph
        .Add oSel.Range, "Addr5"
        oSel.TypeParagraph
        .Add oSel.Range, "Country"
        oSel.TypeParagraph
        .Add oSel.Range, "PostCode"
        oSel.TypeParagraph
        .Add oSel.Range, "PostCode2"
        oSel.TypeParagraph
        oSel.TypeParagraph
        .Add oSel.Range, "Tel_No"
    End With
        'Execute the mail merge
        objWord.MailMerge.Execute
        objWord.Close (0)
    Set oSel = Nothing
    Set objWord = Nothing
    Set objWordApp = Nothing
    
    End Sub
    Thanks

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    I set up the document in word by adding the fields manually. For the users that cannot handle/won't set up Word to do a mail merge, I have created a report in Access that has a large memo field where the user gets to edit the text of the message. Everything else is done by my access program. I have never used TypeParagraph and have never needed to. If it is not working the way you expect, perhaps you could use one of my solutions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •