![]() |
|
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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" |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
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 |