Microsoft Word Mergefield Code to skip certain records

Anonymous
2013-04-24T02:15:02+00:00

Hi

I've been working on a document that imports data from another program into Word 2010 using Mergefields and uses a field called description. With this description field I currently have a code that displays anything with "N-P*" as a blank. My goal is to be able to skip records that have "N-P*" in the description. I have had some success using the following code:

{ MERGEFIELD TableStart:Cost \* MERGEFORMAT }{ NEXTIF \* MERGEFORMAT {MERGEFIELD Description \* MERGEFORMAT } = “N-P*”}

This skips any costs with “N-P*” in the description, but won’t work if there are consecutive records with “N-P*” in the description.  

I would like to be able to skip all records with "N-P*" in the description regardless of whether they are consecutive records or not.

Regards,

Linden

PS. I have also tried using SKIPIF without any success

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

20 answers

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 322.4K Reputation points MVP Volunteer Moderator
    2013-04-24T04:59:56+00:00

    The SKIPIF field should do what you want, but it must be the first field in the mail merge main document.

    { SKIPIF { MERGEFIELD Description } = "N-P*" }

    0 comments No comments
  2. Anonymous
    2013-04-28T22:50:40+00:00

    Hi Doug,

    Thanks for your reply

    I've had a go at trying the SKIPIF field, it sounds exactly like what I want, but for some reason I cannot get it to work. Is the TableStart field which I'm using before it creating problems for SKIPIF?

    eg. { TableStart:Cost }{ SKIPIF { MERGEFIELD Description } = "N-P*" }

    0 comments No comments
  3. Doug Robbins - MVP - Office Apps and Services 322.4K Reputation points MVP Volunteer Moderator
    2013-04-28T23:44:11+00:00

    From where does the { TableStart:Cost } come?  I know of no such field in Word.

    I note that in your original post you mentioned a { MERGEFIELD TableStart:Cost \* MERGEFORMAT }

    Do you have a field in the data source with the name of TableStart:Cost ?

    Regardless, you will note from my response that I said that the SKIPIF field .... MUST BE THE FIRST FIELD IN THE MAIL MERGE MAIN DOCUMENT.

    If you need it, you have use the { MERGEFIELD Description } elsewhere in the document, BUT, the

    { SKIPIF { MERGEFIELD Description } = "N-P*" }

    MUST BE THE FIRST FIELD IN THE MAIL MERGE MAIN DOCUMENT.

    0 comments No comments
  4. Paul Edstein 82,826 Reputation points Volunteer Moderator
    2013-04-28T23:45:53+00:00

    As Doug said, the SKIPIF field should be the first field in the document. So you should be using:

    { SKIPIF { MERGEFIELD Description } = "N-P*" }{MERGEFIELD TableStart:Cost }

    or:

    { SKIPIF«Description» = "N-P*" }«TableStart:Cost»

    Note: The field brace pairs (ie '{ }') for the above examples are created in the body of the document via Ctrl-F9 (Cmd-F9 on a Mac) - you can't simply type them or copy & paste them from this message. Likewise, you can't type or copy & paste the chevrons (ie '« »') - they're part of the actual mergefields, which you can insert from the mailmerge fields dropdown.

    0 comments No comments
  5. Anonymous
    2013-04-29T01:58:01+00:00

    Sorry the { TableStart:Cost } was meant to be { MERGEFIELD TableStart:Cost }

    The information is getting pulled from a cloud based program on the web

    The fields I have set up in a table

    The table requires TableStart and TableEnd fields to build statement lines

    So the coding looks like:

    Item                                                                                            Qty

    { MERGEFIELD TableStart:Cost }{ SKIPIF { MERGEFIELD                     { MERGEFIELD Quantity }

    Description } = "N-P*" }{ MERGEFIELD Description }                        { MERGEFIELD TableEnd:Cost }

    This is what the merged document prints like

    Item                              Qty

    Cabinet                           2

    Bench Top                       1

    N-P Delivery                    1

    I am trying to get it to skip printing the items with N-P in the description

    I have tried using SKIPIF as the first field before the Table:Start:Cost field but nothing seems to work, it just prints everything:

    { SKIPIF { MERGEFIELD Description } = "N-P*" }{ MERGEFIELD TableStart:Cost }{ MERGEFIELD Description }

    { SKIPIF { MERGEFIELD TableStart:Cost }{ MERGEFIELD Description } = "N-P*" }

    I hope this makes sense.

    0 comments No comments