Looping in Word mail merges/ checking for missing fields

I am trying to convert a project that uses WordPerfect merges to use Word mail merges.  One issue that I am encountering is that I cannot find a way to use any looping structures in Word mail merges. Specifically, my data file is a csv text file. 
I control the contents of the file but its current structure is that it will consist of a single record (not counting the header row).  The number of fields will vary but it will contain a field named Person1.  There may or may not be a field named
Person2, Person3 etc.  There are several of these types of fields in the record so it is not an option to make a separate record for each person ie for the record I will have Plaintiff1, Plaintiff2... and Defendant1, Defendant2....
I am having trouble with two things:
1. how can I test for a blank or missing field ie I want to have a statement like {if {MERGEFIELD Defendant2}="" "Defendant is" "Defendants are"}.  That statement works but it throws error messages to the user that the
field Defendant2 is missing and prompts them to substitute another field.  That sort of statement occurs multiple times during a merge so asking the users to ignore the errors is not an option.
2. is there some sort of looping mechanism in Word mail merges.  I need to be able to do two things with a loop:
a.  I need to be able to list each of the Persons, Defendants, Plaintiffs ie. While {MERGEFIELD Defendant{#}<> "" " {MergeFIELD Defendant{#}" (increment variable # by 1).
b.  I some circumstances I need to create full documents based on a loop i.e.  While {MERGEFIELD Defendant{#}<> "" <<merge a defendant summons here>>(increment variable # by 1)

For clarification: In a Word mailmerge, if any of the field headers are missing from the data source, you will get an error. Thus, you can't have a mailmerge main document that references «Plaintiff2» or «Defendant2» and not have the corresponding headers
in the data source. The fields may be empty, but the headers must exist.
Re 1:
You can indeed use an IF test along the lines of:
{IF«Defendant2»= "" "Defendant is" "Defendants are"}
or:
{IF{MERGEFIELD Defendant2}= "" "Defendant is" "Defendants are"}
Re 2a:
Creating a list is as simple as inserting the mergefields one after the other:
«Defendant1»
«Defendant2»
«Defendant3»
This will, of course, result in empty lines when fields have no data. To cater for this, Word provides the mergefield \b and \f switches.Given you can have one or more defendants, you could suppress the extra lines via, say, an \b switch:
1. select the
«Defendant2» field and press Shift-F9 so that you get {MERGEFIELD Defendant2};
2. edit the field code so that you get {MERGEFIELD Defendant2 \b "¶
3. delete the paragraph break or line break after the field, so you get:
«Defendant1»
{MERGEFIELD Defendant2 \b "¶
"}«Defendant3»
where ¶ is a real paragraph/line break
4. Do the same for the «Defendant3» field and so on, till all are done.
The following construction can be used to manage data where one or more related fields («Defendant2», «Defendant3», «Defendant4», «Defendant5», & «Defendant6») may or may not be populated, so you can get commas before all except the last in a multi-defendant
sequence, which is preceded by 'and'.
«Defendant1»{IF«Defendant3»= "" " and «Defendant2»" ", «Defendant2»{IF«Defendant4»= "" " and «Defendant3»" ", «Defendant3»{IF«Defendant5»= "" " and «Defendant4»" ", «Defendant4»{IF«Defendant6»= "" " and «Defendant5»" ", «Defendant5» and «Defendant6»"}"}"}"}
Note: It is assumed that none of the fields after the first empty one will be populated.
Re 2b:
It's not clear what you're after here. However, in addition to using an IF field as per 1, above, they can also be used to conditionally output multiple pages, including text, tables and images, together with additional mergefeilds on those pages. For example:
{IF«Defendant2»= "" "«Defendant2» is a nasty fellow ... plus the rest of defendant 2's content & mergefields"}
Note: The field brace pairs (i.e. '{ }') for the above examples are created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practicable to add them via
any of the standard Word dialogues. Likewise, you can't type or copy & paste the chevrons (i.e. '« »') - they're part of the actual mergefields, which you can insert from the mailmerge toolbar. The spaces represented in the field construction are all required.
Instead of the ¶, you should use real line/paragraph breaks.
For more Word mailmerge tips, see:
http://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html . That page also includes a macro for turning the above field representations into working field codes.
Cheers
Paul Edstein
[MS MVP - Word]

Similar Messages

  • How to check for missing fields in the file?

    Hi friends,
    I have a file to file scenario in which if any of the fields have a blank value, i have to put the file back in the source folder. If none of the fields are missing, the scenario should work normally.
    Can anybody tell me <b>how can i check for the field lengths</b> and if any of the fields are blank, <b>how do i send it back to the original folder.</b>
    Waiting for your responses,
    Divija.

    Hi Divija,
    >><i>how can i check for the field lengths</i>
    Since you need to basically check if the field has a value or not, i dnt think you need to check for the length of the field. Instead, you can use any one of the booloean functions available in the graphical mapping editor to check if the field has a value or not(filed value true or false)
    >><i>how do i send it back to the original folder.</i>
    You can maintain a flag variable in the target structure such that if any of the source fields donot have values, the flag's value becomes 1 else it remains 0.
    Now, you can check if the value of flag is equal to 1/0 in the bpm and accordingly send the data.
    If in case, you donot want the flag to come in the target file that is loaded/sent from the bpm in the end, i think even tat can be taklen care of.
    You can create two receiver communication channels and define one file adapter in each such that one has the destination as the actual target directory and the other has the original source directory as the destination.
    Regards,
    Sushumna

  • Word Mail Merge does not accurately import a Text field in Excel with more than 15 numbers

    Hi, I've looked through some of the discussions regarding importing numbers from excel into word mail merge. I'm having a problem. In Excel I have a column that includes numbers with more than 15 digits. In Excel, I have made this column a text format, so
    now in Excel those long numbers show up correctly. However, when doing a mail merge in Word, again the numbers past 14 digits change to zeros. I've read many help articles about this but am still not finding a solution. I even tried going the DDE route and
    that didn't do it either. I checked out this answer: http://www.techsupportforum.com/forums/f57/mail-merge-data-corruption-429351.html which was the most helpful, but again, DDE seemed to work for this person but not for me. I hope someone can offer a solution.
    I was hoping that I could do a picture switch, but that does not seem to be an option for this particular problem. I don't know why importing it in DDE format did not solve the problem. Thanks for any help!

    Wow! After all my searching and just after posting this I figured out the solution! I originally had { MERGEFIELD Field_Name \# # } But then I just removed everything after the field name, as is normal for any other text field, so not indicating it was
    a number, and now it shows up correctly even if the number (from a Text formatted field in Excel) is longer than 15 digits. Hope this helps anyone else who has a problem. I did not use DDE to solve this problem.

  • Difficulty cross-referencing PDF created from MS Word Mail Merge

    Hello!
    I'm using MS Word Mail Merge to create PDF documents with Adobe Acrobat 9 (Merge to Adobe PDF ribbon). Adobe allows me to specify the file name to use, which Adobe uses for the first portion of the file name, but the remaining is up to Adobe and varies depending on the total number of documents.
    The help shows as: "The PDF will be named using this text plus a series of numbers. For example, if you type JulyLetter in the Specify PDF File Name box, the mail-merged PDFs might appear as JulyLetter_0000123, JulyLetter_0000124, July Letter_0000125, and so forth."
    If the numbering was sequential, there wouldn't be a problem. However, if the number of records exceeds 50 documents, the convention changes at intervals of 50 and it makes it difficult to cross-reference without opening the document.
    As an example, if there are a total of 67 documents, you get the following results:
    Record 15 is named JulyLetter_15015.pdf. (meaning range 1-50, record 15)
    Record 20 is named JulyLetter_15020.pdf (meaning range 1-50, record 20)
    Record 56 is named JulyLetter_51676.pdf (meaning range 51-67, record 6)
    Record 66 is named JulyLetter_516716.pdf (meaning range 51-67, record 16)
    The breaks are at intervals of 50 records, meaning that if there were 230 records to print, record 143 would be JulyLetter_10115043.pdf, record 180 would be JulyLetter_15120030.pdf.
    Does anyone know where the naming or breaks are controlled within Adobe to just keep it sequential or if there is possibly a cross reference file created that may assist with cataloging?
    Thanks

    In each of the successive versions of Acrobat to the version you have, improvements have been made in converting a PDF to Word format. Acrobat X and the version about to come out, Acrobat XI, do the best job. I can't guarantee that the results would be an improvement in your case, but I have a hunch they would.

  • MS-Word mail merge funcionality

    I would like to have an editor with functionalities similar to MS-Word's mail merge. My website should be able to publish templates with dynamic data, from an external database. Can I have it with Muse or any other Adobe product ?

    I have the same requirement...ms-word mail merge thru Java(before uploading to server..well that is what I think of doing).
    1)Any success with this?
    2)How did you do that in ASP? Any links you could suggest?
    3)What did you use with the ASP setup to fax out(meaning the fax server)
    Is it possible to create a word document with dynamic
    contents (thru a template) using jsp or java.
    Actually, I want to use mail merge facility to create
    a Word Document to fax in jsp.
    I know it is possible in asp/vb. But no idea,,, How
    can it done in jsp???????

  • Check for missing pages

    At work we are using a scanner with a feeder to digitalize many of our company documents. On the first manual check I found there to be a few missing pages. If there a way to automate the "missing page check". Can i write a script to check for missing pages. I am fairly new to acrobat and OCR, but I am knowledgeable in programming. Any help would be appreciated.

    The script as follows will give you the total number of pages in a document:
    console.println("There are " + this.numPages + " pages in this document");
    Also go the the following link for the Adobe Development Centre - Documentation and References - Acrobat 9.1 SDK Documentation
    There is a Javascript for API Reference which will give you some guidance.
    http://www.adobe.com/devnet/acrobat.html

  • Word Mail Merge

    I am using the following code to mail merge data in a table into a Word document:
    call function 'MS_WORD_OLE_FORMLETTER'
          exporting
            WORD_DOCUMENT             = FILEFORM
            HIDDEN                    = 0
            WORD_PASSWORD             =
            PASSWORD_OPTION           = 1
            FILE_NAME                 = FILEDATA
            NEW_DOCUMENT              =
            DOWNLOAD_PATH             = FILEPATH
           PRINT                     = PFPRINT
          tables
            DATA_TAB                  = FDATA
            FIELDNAMES                = FIELDS
         exceptions
           INVALID_FIELDNAMES        = 1
           USER_CANCELLED            = 2
           DOWNLOAD_PROBLEM          = 3
           COMMUNICATION_ERROR       = 4
           others                    = 5.
    Fdata has both text and numeric data in fileds F1, F2, F3,...Fn
    FIELDS has one field containing rows with text data corresponding to the field names of Fdata i.e F1, F2, F3,...Fn.
    My program does not open my word mail merge template, FILEDATA, automatically to fill it with contents of Fdata. Instead a new document is opened with the message "Insert the mail merge fields" and a pop up window asking which filed and record delimeters to use. Where am I going wwrong?

    I will rephrase my question:
    How does the function module 'MS_WORD_OLE_FORMLETTER' work?
    My understnading is that:
    1. WORD_DOCUMENT  is the document that contains the merge fields which will be filled with data. It is the final document that will appear after the function has been executed.
    2. File_Name is the file (can be word document) that will be used as the data source by word_document.
    3. DOWNLOAD_PATH is were File_name is located.
    4. DATA_TAB  contains the merge data. Its contents will be written onto File_name.
    5. FIELDNAMES is he internal table containing the field names that correspond to the fields on WORD_DOCUMENT. It also writes its contants to File_Name.
    Since the data source of a mail merge document should have delimited fields, how do I go about this in the File_Name?
    Regards,

  • Can my mail automatically check for emails?

    can my iphone mail automatically check for emails without having to open the mail app. i remember before the update there was an option where it would check every 15 minutes. what ever happened to that? is there another way to do it? thanks in advance!

    Depending on your Mail client ie MobileMe/Yahoo/Gmail you can either set up push which is great or failing that set up fetch mail where it checks at certain intervals look in:
    Settings>Fetch New Data>
    clicking on the Mail app does a check each time you open it, setting fetch/push means it will either have the mail sent to your phone(Push) or go out and "fetch" the mail without you having to manually do it.

  • Check for required fields before locking subforms and submitting

    Hello,
    I have a 5-page form with many questions, to be completed by the original requestor and multiple approvers.  What I'm trying to do is have the original requestor's Submit button on p. 3 lock the input on the first three pages, but first check if all those fields have some content.  I currently have all the fields on pp. 1-3 set to "Required" in the object properties, but my script still locks them when there's is one empty one.  Here's what I have:
    //Lock portions of form
    Page1.access = "readOnly"
    Page2.access = "readOnly"
    Page3.access = "readOnly"
    //Save document, allow user to change name
    app.execMenuItem("SaveAs");
    //Submit via e-mail
    Submit_REAL.event__click.submit.target = "mailto:[email protected]" +
    "?subject=Subject text" +
    "&body=Message";
    Submit_REAL.execEvent("click");
    The automatic check for required fields happens after the pages get locked.  I would like the check to stop the process before it locks the pages.  Is there any way to check all at once that all "Required" fields on those pages have some content before allowing the script to proceed?  I know how to script it to manually check the 50 or so questions on those pages, but I would like to avoid that.  Thanks for any help.

    There are a few problems that I can see from the start. First, your code is going to pick up EVERY node that exists on these pages. Some of those nodes will not have a rawValue, and some will not have an actual name. As an example, you can take your code and create a text field to dump all of the names of the nodes that you get when you pull in all of the nodes this way. Here's an example:
    The result:
    Now, the question is, do you have a consistent naming convention for your fields that might be empty? That could be text fields, radio button lists, etc. For instance, I always prefix the names of objects in order to more easily keep track of what they are in scripts. Since I'm doing that, I can check the name of the field for tf, nf, rbl, cb, or whatever I have included to make sure that I'm checking an actual field before I check for things like rawValue.
    var nodeName = oNodes.item(nNodeCount).name;
    if (nodeName.indexOf("tf")>-1 || nodeName.indexOf("rbl") > -1 || /*check other field types*/) {
      //insert your code to check for empty answers here
    As for your line 7 issue. The syntax problem is that you've put extra parentheses in your if statement. Take out the parentheses that are just before and after the or "||".
    *This is my fourth attempt to reply. Something was going on with Adobe/Jive earlier, I suppose.

  • How can I enforce automatic spell checking for selected fields of data entered by form users?

    I'd like to be able to enforce spell checking of selected fields in the forms that I've created using LiveCycle Designer 8.2 at run time, as opposed to design time.  I understand the version LCD 8 has a nifty new spell checker for form designers.  But I want to spell check the data entered by users using Acrobat Reader.  And I want to enforce the spell checking automatically on selected fields only.
    Presently it seems that users filling in my forms, must know how to manually right-click on each field and select "Spell Check" from the resulting dialog box in order to check for spelling errors in the data the user has entered in the form.
    I would like to discover a way to enforce spell checking in selected fields, just as I am able to do in forms created using Acrobat Pro.  In Acrobat Pro, I can set a property for each field to require spell checking.  but that feature seems to be missing in Livecycle Designer.
    I've check the Object model for XFA forms hoping that I might find a method I can call with a Javascript, to check spelling based on an event such as onBlur.  But I haven't found a spell check method.
    Am I missing something simple?  Is there a way to set each field to be spell checked when a user is filling in the form using the free Acrobat Reader?
    Our users are not sophisticated and requiring them to spell check each field separately just won't cut it...
    Any help on this will be greatly appreciated.
    Thanks!
    -David Bartholomew

    Hi David,
    Two things...
    At design time set the locale of the form to one that Acrobat spell checks. For example English (US) and English (UK) locales have spell checkers; however English (Ireland) does not. Check the Warnings tab to see if spell checking is supported for your locale.
    If your form locale supports spell checking then you can go to the button script below.
    If you form locale does NOT support spell checking then Stephanie has a great work around to force spell checking (http://forums.adobe.com/message/2233945#2233945).
    Bring a regular button onto the form and in the click event have the following:
    app.execMenuItem("Spelling:Check Spelling");
    Which will open the spell checker for all fields.  Thanks to Paul for extracting all of the accessible menu items (http://forums.adobe.com/message/1912914#1912914).
    Good luck,
    Niall

  • Word Mail Merge using Powershell

    Hi all,
    I'm working on a script that automates account creation and notification for our students. I've completed a significant chunk of the script and have it successfully creating AD accounts and e-mailing students their credentials to access our system from
    a batch job that runs nightly. I want to add an additional part that will create a document using a Microsoft word template that is associated with a CSV file that the script will be populating each day it runs. The goal is to create a mail merged PDF that
    I can give to our admissions folks that has all the pertinent information for students to login. They will put these documents in their admissions packets or hand them to new students so they can login to the student system. I think I'm almost there as
    I can get word to create a PDF of the template. The only problem is I have no idea how to get it to execute the mail merge so that the pdf contains the actual data I need it to. Currently all I end up with is an export of the template itself in PDF
    format.
    I'm sure the problem with this is that I'm having trouble calling the .net functions for Word via powershell. Online I see various documents on how to do this with vb.net however Powershell instructions seem to not exist. I'm sure the actions are quite similar
    but I need some help. Here is the section of the code I have currently:
    $filename = "EmailTemplate1.dotx"
    $filename2 = "EmailTemplateProc.pdf"
    $word=new-object -com Word.Application
    $doc=$word.Documents.Add($filename)
    $word.Visible=$False
    $word.ActiveDocument.Fields.Update()
    $doc.WdMailMergeDestination.wdSendToNewDocument
    $word.ActiveDocument
    $Doc.saveas([ref] $filename2, [ref] 17)
    $Doc.close()
    $word.Quit()
    I'm sure the problem lies somewhere at the $doc.WdMailMergeDestination and onward. Basically I want it to take the dotx file which already has the templated document with mail merged fields and save an executed mail merge as a PDF. Any insight
    would be great.
    Thanks in advance!

    Not quite sure about that command line thing. I looked all through the support doc you posted and see nothing mentioning executing a mail merge via the command line. Is there something else i'm missing here? Can it be done with a macro?
    Like I posted.  As how to do a mail merge in the Word forum.  You can run a macro from the command line or you can trigger the merge from a startup macro.   The macros will reside in a template which will be specified on the command line
    alone with the new document name and location.
    You can create the macro in a minute with the macro recorder.
    ¯\_(ツ)_/¯

  • I get an error trying to use Apple Address Book with Word Mail merge - says it cannot open data file?

    I am running MS Word 2011, latest Mac OS, and trying to use the Mail Merge option with the Apple Address Book as the data source.
    However whenever I select the Apple Address Book as the data source, I get the error "Word was unable to open the data source".
    Anybody got any idea why?
    Thanks for your help

    I am guessing you could have solved this little problem already but perhaps someone else may benefit:
    I struggled with the same problem - not being able to use Mac Address Book (i.e. Contacts) with Word 2013 for mac mail-merge (on Mountain Lion and, now, on Mavericks) - with the exact same error message reported by Klausngigtoas above .
    So I read lots of techie stuff on forums which passed a nice few hours but didn't help. Finally, with slumped, defeated expression, I gave up.
    But I just now (such is life) I accidentally stumbled upon the simple solution:
    1. Enter System Preferences and click Security & Privacy.
    2. Select the Privacy tab and then on Contacts on the left hand panel.
    3. In the right hand panel ("Allow the apps below to access your contacts") just tick the Contacts box.
    4. And Voilà! - at least it worked for me - hope it does for you.

  • Word Mail Merge Macro

    Greetings,
    I have generated the below macro and running it. It's basically a mail merge macro which reads from a fixed file position and emails the document upon prompting the user. It works perfectly except for one small, critical issue. If one of the recipients is
    deselected, I get a run time error 5853 Invalid parameter and the below line is highlighted.
    ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
    The full code block can be found below. Any help is appreciated alot.
    Sub MailMergeMacro()
    Dim Choice As Integer
    Response = MsgBox(prompt:="Select 'Yes' or 'No'.", Buttons:=vbYesNo)
    If Response = vbYes Then
    Application.Dialogs(wdDialogMailMergeRecipients).Show
    ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
    wdFieldAddressBlock, Text:= _
    "\f ""<<_TITLE0_ >><<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>" & Chr(13) & "<<_COMPANY_" & Chr(13) & ">><<_STREET1_" & Chr(13) & ">><<_STREET2_" & Chr(13) & ">><<_CITY_" & Chr(13) & ">><<_STATE_" & Chr(13) & ">><<_POSTAL_>><<" & Chr(13) & "_COUNTRY_>>"" \l 2057 \c 2 \e ""Un"
    Selection.TypeParagraph
    Selection.TypeParagraph
    ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
    wdFieldGreetingLine, Text:= _
    "\f ""<<_BEFORE_ Dear >><<_TITLE0_>><< _LAST0_>>" & Chr(10) & "<<_AFTER_ ,>>"" \l 2057 \e ""Dear Sir or Madam,"""
    Selection.TypeParagraph
    ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
    With ActiveDocument.MailMerge
    .Destination = wdSendToEmail
    .SuppressBlankLines = True
    With .DataSource
    .FirstRecord = wdDefaultFirstRecord
    .LastRecord = wdDefaultLastRecord
    End With
    .Execute Pause:=False
    End With
    MsgBox "The document has been mailed"
    Else
    MsgBox "The document has not been mailed"
    End If
    End Sub
    Thanks again, Regards

    Hi,
    Since you need help with Macro, I suggest you post the question in Word for Developers forum to get further assistance:
    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
    Regards,
    Melon Chen
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Repeating Word Mail-Merge

    I have an entity called Tenant.
    In the Tenant entity there is a form with fields such as Tenant Name, Tenant Address.
    I record the Name and Address of the Tenants in the appropriate fields.
    I want to do a mail merge based on the Tenant entity that when it is ran a separate document containing the Tenant Name and Tenant Address is produced for each separate record in the Tenant entity.
    Anyone know how I could do this?

    check these:-
    http://www.microsoft.com/en-us/dynamics/crm-customer-center/work-with-mail-merge-templates.aspx
    http://www.magnetismsolutions.com/blog/colinmaitland/2013/12/16/microsoft-dynamics-crm-2013-mail-merge
    Regards Faisal

  • Open Word mail merge and print

    Hi!
    Any help on this would be much appreciated!
    I fear i may be asking too much but is there anyway using powershell to open a particular word document that is linked to an excel document for a mail merge, and automatically print the last record?
    Thanks!

    Hey,
    I'm relatively new to powershell and the great things it can do. But I used Google to see what would come up as a result. I found
    this and
    this which could be a great start for you.
    If I had the time I would test this out myself and post back some findings as this looks like quite the interesting request.
    If this is helpful please mark it so. Also if this solved your problem mark as answer.

Maybe you are looking for

  • Excise details are not comming in the GRN

    Hi,   I am using SAP B ONE 2007 PL 10 and faciung the problem while making GRN by making an add on, my add on take information like PO no(DocEntry), Item code, Qty from user and makes GRN internally in this case SAP is required to find out tax code f

  • How to make a text field wrap to next page

    I've done my best to find the solution to my problem before coming here to post, so forgive me if I've missed a previously posted solution. I am a .NET coder, using iText to manipulate PDF's.  I need to create a template for a corporate invoice that

  • My ipod is disabled forgot p.w. i dont know how to connect w/ itunes?

    Forgot my p.w. now my ipod touch is diabled connect to itunes displayed on the front screen.How do I connect to itunes?

  • How do I create a song in key of Ab Minor

    Is it possible to create a song in garageband in Aflat minor? If so, how? Thanks Kate

  • Off-Topic: Unresponsive FTP server

    What's the deal with Oracle's FTP Server? Everything used to be smooth, no matter what day or time. Now you get: * User ftp access denied. Not logged in. * If you ever do log in, and start GET, the transfer rate gets slower and slower 'til you get no