Solved

Word Merge with Repeating Rows - I am close

Posted on 2014-09-23
5
244 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 500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

740 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