Results 1 to 2 of 2
  1. #1
    Rachelkm2 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2009
    Posts
    1

    Mail Merge from Access to Word

    I have a mail merge function which is supposed to merge the records (multiple) from a query (in which the user selects different criteria) into a letter in Word.



    The merge works - except that it only merges the first record. I want to be able to merge all the results of the query into the document, producing several personalized letters. The code is outlined below, if anyone can help me figure out what I'm doing wrong, it would be greatly appreciated.

    Private Sub cmdPrintLetterReport_Click()
    Dim Whereclause As String
    If Not IsNull(Me.cboFilterLocalNumber) Then
    Whereclause = Whereclause & "([Local#] = """ & Me.cboFilterLocalNumber & """) And "
    End If
    If Not IsNull(Me.cboFilterLocalType) Then
    Whereclause = Whereclause & "([LocalType] = """ & Me.cboFilterLocalType & """) And "
    End If
    If Not IsNull(Me.cboFilterAgeTo) Then
    Whereclause = Whereclause & "([Age] < " & (Me.cboFilterAgeTo + 1) & ") AND "
    End If
    If Not IsNull(Me.cboFilterPartyAffiliation) Then
    Whereclause = Whereclause & "([PartyAffiliation] = """ & Me.cboFilterPartyAffiliation & """) And """
    End If
    lngLen = Len(Whereclause) - 5
    If lngLen <= 0 Then
    MsgBox "No criteria", vbInformation, "Nothing to do."
    Else
    Whereclause = Left$(Whereclause, lngLen)
    Debug.Print Whereclause
    Me.Filter = Whereclause
    Me.FilterOn = True
    End If
    Dim AddyLineVar As String, SalutationVar As String
    SalutationVar = "Dear Friend and Brother;"
    AddyLineVar = AddyLineVar & vbCrLf & [Mailing Name]
    AddyLineVar = AddyLineVar & vbCrLf & [AddressLine1]
    If Not IsNull([AddressLine2]) Then
    AddyLineVar = AddyLineVar & vbCrLf & [AddressLine2]
    End If
    AddyLineVar = AddyLineVar & vbCrLf & [City State Zip]
    Dim Wrd As New Word.Application
    Set Wrd = CreateObject("Word.Application")
    Dim MergeDoc As String
    MergeDoc = Application.CurrentProject.Path
    MergeDoc = MergeDoc & "\FPTC Letter Template.dotx"
    Wrd.Documents.Add MergeDoc
    Wrd.Visible = True
    With Wrd.ActiveDocument.Bookmarks
    .Item("TodaysDate").Range.Text = Date
    .Item("AddressLines").Range.Text = AddyLineVar
    .Item("Salutation").Range.Text = SalutationVar
    End With
    End Sub

    Thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    See if the Super Easy Word Merge link helps at all. Scroll down 'til you see it.

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

Similar Threads

  1. Amount in word in MS. Access 2000 (VBA)
    By dannygan in forum Access
    Replies: 5
    Last Post: 06-07-2009, 11:52 PM
  2. access to word please help!
    By fiesta_rich in forum Import/Export Data
    Replies: 2
    Last Post: 04-14-2009, 09:27 PM
  3. Word document INTO Access form
    By jonathonhicks in forum Forms
    Replies: 0
    Last Post: 04-30-2007, 05:59 PM
  4. Mail merge
    By grgerhard in forum Forms
    Replies: 0
    Last Post: 04-25-2006, 05:06 PM
  5. Mail Merge problem
    By kfergus in forum Programming
    Replies: 0
    Last Post: 04-24-2006, 01:06 PM

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