Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Programming

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 05-29-2009, 07:50 AM
Rachelkm2 Rachelkm2 is offline Windows Vista Access 2007 (version 12.0)
Novice
 
Join Date: May 2009
Posts: 1
Rachelkm2 is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 05-29-2009, 12:49 PM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

See if the Super Easy Word Merge link helps at all. Scroll down 'til you see it.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Amount in word in MS. Access 2000 (VBA) dannygan Access 5 06-07-2009 09:52 PM
access to word please help! fiesta_rich Import/Export Data 2 04-14-2009 07:27 PM
Word document INTO Access form jonathonhicks Forms 0 04-30-2007 03:59 PM
Mail merge grgerhard Forms 0 04-25-2006 03:06 PM
Mail Merge problem kfergus Programming 0 04-24-2006 11:06 AM


All times are GMT -8. The time now is 02:36 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.