mailmergeword-2013

Mail Merge in Word Does Not Move to Next Field and Input Value


I'm running a Mail Merge using Word 2013. I have a list with 3 items on it [Fig. 3], and I have a template that I've written. The template has some basic formatting and displays the line items (1 on each line) with the calculated Total Shipping (Freight), Total before tax, Total VAT amount and Grand Total in separate lines below that. To get to the next line item I am using the NEXT record rule. Each line item shows on its own line, but the Total Shipping, Total before tax and Grand Total do not populate unless I manually update the fields [Fig. 1]. I have played with the NEXTIF rule and I can get those fields to update automatically, but I have 5 lines in the item table and the other lines fill with the first record [Fig. 2]. Can anyone point me in the right direction here? End goal is to have anything from 1 to 5 records/line items in the table and for the bottom fields to populate during the mailmerge.

The NEXTIF rule is populated like so: { NEXTIF { MERGEFIELD "Product_Product_ID" } = "True" }

Thank you kindly

Screenshot of my populated table using NEXT: enter image description here

Screenshot of populated table using NEXTIF: enter image description here

Screenshot of the data table: enter image description here


Solution

  • I am testing using Windows Word 2010. It is possible that other versions (particularly on Mac) behave differently, so let us know which version you are using.

    Previously, I had assumed that you were doing a one-many merge (with data for multiple pages, but a maximum of 5 rows per page). Now I read your text again, I realise you data source probably really does have a maximum of 5 rows, and that you were seeking a way to detect the non-existence of a row. Assuming that is the case, then...

    It's important that you are "completing the merge", i.e. outputting to a new document, or whatever. Previewing the merge only gives you an indication of what is going to happen, and can sometimes be misleading.

    To test for non-existence, you should be able to test

    { IF  { MERGEFIELD Product_ID } = "" }
    

    as I indicated in my previous comment. Although there may be times when that does not display the expected result during preview, it should display the expected result when you complete the merge. (It will probably only require a field update to display correctly during preview.

    I suspect that the issue related to non-display of totals is related to the way you are calculating them. If you are using a running total and not checking the existence of a value in every row, things will probably go wrong. You are clearly doing it differently from me, as I actually see an error message in my total:

    !Unexpected end of formula.
    

    That's if I do it by having the following at the beginning of the page

    { SET Total 0 }
    

    and the following calculation in each row

    { SET Total { =Total+{ MERGEFIELD Extended_Amount } } }
    

    To fix that, I think you would need to do something like

    { SET Total { =Total+{ IF { MERGEFIELD Extended_Amount } = "" 0 { MERGEFIELD Extended_Amount } } } }
    

    However, another for that calculation you could use a completely different approach - select the table, insert a bookmark, let's say "datatable", then use a field like

    { =SUM(datatable [F:F]) }
    

    or if you want the field code to be resolved in an output document, use

    { QUOTE { =SUM(datatable [F:F]) } }
    

    If you are doing a one-many merge (more than 5 records in your data source) then the { NEXT } field approach will not work. I can detail what you need to do, but the outline is that you have to have something that tells you when a page's data ends, and use that to suppress the output of rows that should not be there. (An alternative that some might consider to be simpler might be to have a row count in the first row for each page, and have an IF block that inserts the correct number of table rows+contents depending on the row count_.