?
Solved

Word Merge with Repeating Rows - I am close

Posted on 2014-09-23
5
Medium Priority
?
262 Views
Last Modified: 2014-09-28
I have done lots of research on this and am close but there is something I don't understand on how Merge processes the data. It is a classic example. I have a spreadsheet that has multiple rows per person. Each row has some repeating fields (name address etc) and then some unique fields (a CODE, STATUS, and NOTE). I want to create a merge letter that lists all of a persons CODEs+Status+Notes on a single page.

So turn this:
12345 Steve ABC  OPEN  Steve has an open ABC item
12345 Steve XYZ   CLOSED Steve has a closed XYZ item

Into this:

Dear Steve;

Here is some info for you.

ABC   OPEN      Steve has an open ABC Item
XYZ    CLOSED  Steve has a closed xyz item

Sincerely,
Your friend

Using the below code I am able to get the merge to only print the repeating data on the first page, but it still jumps to a new page for each of the repeating items (ABC...   XYZ... each on a separate page).

Here is the code - - thanks very much for any help you can provide. I have included the results of the merge also.

{ IF { MERGESEQ } = "1" "{MERGEFIELD ID }" " " }{SET Place1 { MERGEFIELD ID }}
{Place1}
{Place2}
{ IF { Place2} <> {Place1} "{MERGEFIELD ID } { MERGEFIELD CODE } { MERGEFIELD STATUS } { MERGEFIELD NOTE }"  "{ MERGEFIELD CODE } { MERGEFIELD STATUS } { MERGEFIELD NOTE }"}{SET Place2 {MERGEFIELD ID}}
0
Comment
Question by:COBOLforever
  • 4
5 Comments
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 40341984
I think you would do better using Automation code to do the merge.  Your project seems to require two linked tables, one for person records, one for status records, with (possibly) multiple records per person.  This is similar to the creation of a Word Northwind invoice, covered in my old Access Archon #44 (Merging to Word from Linked Access Tables), updated in my Working with Word ebook.  The code uses doc properties to write the main record's data to the Word document, and TypeText to fill in a table with item details, as many as are needed per invoice.  Here is a link for the article:

http://www.helenfeddema.com/Files/accarch44.zip
0
 

Author Comment

by:COBOLforever
ID: 40342558
Thanks Helen - -that is a nice piece of work, but I know it is much easier than that now. If I were to try your method, I have a Memo field - -how does that fit into your scenario?

Thanks much,
-Jason
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 40344889
For a Memo field, you could try using a bookmark and pasting the contents of the Memo field to the bookmark.  DocProperty fields are too small for that.
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 40344905
My Working with Word ebook (3rd edition coming out soon) has an example of writing data to Word using bookmarks.  The example just copies a block of text from an unbound textbox to write to the bookmark, but it would most likely work with text from a Memo field too.  Here is the code that writes data from the textbox to various bookmarks in a Word document:

      'Open a new letter based on the selected template
      Set doc = appWord.Documents.Add(strTemplateNameAndPath)
      
      'Write information to Word bookmarks
      strBookmark = "Name"
      Call UpdateBookmark(doc, strBookmark, strContactNameAndJob)
      
      strBookmark = "Address"
      Call UpdateBookmark(doc, strBookmark, strAddress)
      
      strBookmark = "CompanyName"
      Call UpdateBookmark(doc, strBookmark, strCompanyName)
      
      strBookmark = "Salutation"
      Call UpdateBookmark(doc, strBookmark, strSalutation)
               
      strBookmark = "TodayDate"
      Call UpdateBookmark(doc, strBookmark, strLongDate)
      
      strBookmark = "EnvelopeName"
      Call UpdateBookmark(doc, strBookmark, strContactNameAndJob)
      
      strBookmark = "EnvelopeCompany"
      Call UpdateBookmark(doc, strBookmark, strCompanyName)
         
      strBookmark = "EnvelopeAddress"
      Call UpdateBookmark(doc, strBookmark, strAddress)
      
      If strTemplateName = "Contact Letter BM.dotx" Then
         strBookmark = "LetterBody"
         Call UpdateBookmark(doc, strBookmark, Me![txtLetterText].Value)
      End If
      

Open in new window

The variables are set from listbox columns, except for strBookmark.  The UpdateBookmark procedure is listed below:

Public Sub UpdateBookmark(doc As Word.Document, _
   strBookmark As String, strText As String)
'Created by Helen Feddema 6-Jun-2014
'Last modified by Helen Feddema 6-Jun-2014

On Error GoTo ErrorHandler

   Dim rngBM As Range
   
   If doc.Bookmarks.Exists(strBookmark) = True Then
      Set rngBM = doc.Bookmarks(strBookmark).Range
      rngBM.Text = strText
      doc.Bookmarks.Add strBookmark, rngBM
   End If
   
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & " in UpdateBookmark procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit
   
 End Sub

Open in new window

0
 
LVL 31

Accepted Solution

by:
Helen Feddema earned 2000 total points
ID: 40344911
Or, if the Word document has tables, the Memo field data could be written to a specific cell in a table, as in the Northwind Invoice code.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question