Consulting

Results 1 to 2 of 2

Thread: Help W Access 2010 Mail Merge to Word

  1. #1
    VBAX Newbie
    Joined
    Feb 2019
    Posts
    1
    Location

    Help W Access 2010 Mail Merge to Word

    can't seem to get this code to work, any thoughts appreciated
    Bud

    Function MergeIt(strWordFile As String, Optional lngEvent As Long, Optional alternate As Long) As Boolean
    Dim objWord As Word.Document
    Dim strFileLocation As String, mysql As String
    Dim myDB As Database, rst As DAO.Recordset, RecNumber As Long
    Dim strConnect As String, strSql As String



    MergeIt = False
    Set myDB = CurrentDb()
    mysql = "Select * from zstblBackEnds"
    Set rst = myDB.OpenRecordset(mysql, dbOpenSnapshot)

    strFileLocation = rst("Path") & "" & strWordFile 'file location


    strConnect = "Table tmpDonors-Generic" 'connection
    strSql = "select * from [tmpDonors-Generic]"



    Set objWord = GetObject(strFileLocation, "Word.Document")


    objWord.Application.Visible = False

    ' Set the mail merge data source as the OLF Front End database.

    With objWord.MailMerge
    .OpenDataSource _
    Name:="C:\my Documents\OurLady2003.mdb", _
    AddToRecentFiles:=False, _
    LinkToSource:=True, _
    Connection:=strConnect, _
    SQLStatement:=strSql

    .Destination = wdSendToNewDocument
    .Execute Pause:=False
    End With

    ' Execute the mail merge.

    objWord.MailMerge.Execute

    End If
    rst.Close
    Set rst = Nothing
    Set myDB = Nothing
    End Function

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Your "Connection:=strConnect", populated as it is via "strConnect = "Table tmpDonors-Generic" 'connection" is incomplete. For an idea of what's required, see Run a Mailmerge from Excel, Sending the Output to Individual Files in the Mailmerge Tips and Tricks thread at:
    http://www.msofficeforums.com/mail-m...ps-tricks.html
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

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