• { NEXTIF Expression1 Operator Expression2 }

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » { NEXTIF Expression1 Operator Expression2 }

    Author
    Topic
    #458174

    With respect to {NEXTIF}, I wish to know:
    1. Whether the logical comparison is true or false, does the {NEXTIF} always move the record pointer forward in the data source (Access, Excel, csv,…etc.) in any case?
    2. Then, what’s the difference between the comparison results–true and false?
    3. If the comparison is true, does it initiate a page break?
    4. Is {NEXTIF} normally used in non-directory document types?
    5. As far as the field codes are concerned, what’s the difference between Directory and other document types? It seems to me that setting the document type to Directory adds more flexibility to the field coding because it doesn’t add page breaks record by record.
    6. What’s the difference between the {NEXT} and {NEXTIF}?
    7. Is there any field code which allows moving the record pointer backward?

    Thanks in advance.

    Armstrong

    Viewing 0 reply threads
    Author
    Replies
    • #1151314

      1. Whether the logical comparison is true or false, does the {NEXTIF} always move the record pointer forward in the data source (Access, Excel, csv,…etc.) in any case?

      If the condition is true, the next record is combined with the current one as if they were one record.
      If the condition is false, the merge continues as if there had been no NEXTIF field.

      2. Then, what’s the difference between the comparison results–true and false?

      See above.

      3. If the comparison is true, does it initiate a page break?

      No, unless you explicitly insert a page or section break. If the condition is true, the data from the current record and the next record will be combined as if they were a single record.

      4. Is {NEXTIF} normally used in non-directory document types?

      It could be used for mailing labels, for example if you want to combine multiple names on one label based on a condition.

      5. As far as the field codes are concerned, what’s the difference between Directory and other document types? It seems to me that setting the document type to Directory adds more flexibility to the field coding because it doesn’t add page breaks record by record.

      With a letter-type merge, a next-page section break is inserted after each record. With a directory-type merge, you can print a list of records on a single page (or as many pages as needed).

      6. What’s the difference between the {NEXT} and {NEXTIF}?

      The NEXT field combines the next record with the current record unconditionally. It is used to move to the next label on the same page in label-type merges.

      7. Is there any field code which allows moving the record pointer backward?

      No, you cannot move backwards through the data source. If you really need that, you’d have to write VBA code that opens a recordset, reads its data and fills the document as needed.

      • #1151382

        Hi Hans,
        Thanks for your absolutely thorough explanation, far more exceeding Microsoft’s.
        Nonetheless I’m confused by “the next record is combined with the current one as if they were one record.”
        Questions:
        1. How could it be technically possible with respect to {MergeField}? Say, the current record pointer is Record 1 and the comparison is TRUE, how would {MergeField} in this scenario?
        {IF {MergeRec} = 1 {SET KEY {MergeField CustID}}}

        /* Before the following {NEXTIF} field, the current Record Pointer is 1 (the first record) */
        {NEXTIF {MergeField CustID} = {Key}}{MergeField CustID}

        2. Here now comes the most challenging question. In {NEXTIF {MergeField CustID} = {Key}}, which record, Record 1 or Record 2, does the comparison {MergeField CustID} = {Key} base on? That’s, does the CustID in the comparison belong to the Record 1 or Record 2? That’s, in the general, does the comparison base on the NEXT record? That’s, when executing {NEXTIF}, does the record pointer already move forward before performing the comparison?

        Thanks for your enormous help.

        Armstrong

        • #1151384

          I don’t understand your first question “How would {MergeField} in this scenario?” Did you omit something?

          About the second question: the condition in the NEXTIF field is evaluated in order to see IF the merge should move to the next record. So the condition is necessarily evaluated BEFORE moving to the next record. In your example, Word looks at the value of CustID in the first record. and compares it to Key.

          • #1151405

            Hi Hans,
            Thanks for your fast reply. I did test it myself. Yes, {NEXTIF} actually performs the comparison first.
            In my case, for example, {NEXTIF {MergeField CustID} = “XYZ” } performs the comparison on the current record.

            Referring to Microsoft’s official description http://office.microsoft.com/en-us/word/HP100779671033.aspx:
            “The NEXTIF field compares two expressions. If the comparison is true, Microsoft Office Word merges the next data record (data record: A complete set of related information that corresponds to one row of information in the data source. All information about one client in a client mailing list is an example of a data record.) into the current merge document. If the comparison is false, Word merges the next data record into a new merge document.”
            It’s slightly different than yours. Specifically, “If the comparison is false, Word merges the next data record into a new merge document.”
            That’s how it causes confusion to me.

            Thanks for your help.

            Regards,
            Armstrong

            • #1151410

              The sentence “If the comparison is false, Word merges the next data record into a new merge document.” must be read as follows for letter-type merges:

              If the condition evaluates to true, Word merges the next record into the current letter.
              If the condition evaluates to false, Word merges the next record into a new letter.

            • #1151434

              Hi Hans,

              Thanks for adding clarity. I wish you were the author of most Microsoft user manuals.
              So for “Letters” document type, {NEXTIF} does insert a form feed. Does it? Now at least we agree {NEXTIF} can “merge the next record into a new letter” if the condition is FALSE. In actuality, how? Does it generate a form feed immediately upon finding the condition FALSE?
              Also, in your first reply, you state, “If the condition is false, the merge continues as if there had been no NEXTIF field.”

              That’s exactly where I was confused. Please help. Thanks.

              Armstrong

            • #1151607

              Hi Hans,
              Please reply my last post. In particular, on the one hand, you state, “If the condition is false, the merge continues as if there had been no NEXTIF field.” On the other hand, you state, “If the condition evaluates to false, Word merges the next record into a new letter.”
              Please help me understand the confusion. Thanks.

              Armstrong

            • #1151612

              Perhaps this illustration will help. If not, I suggest that you try out a mail merge with a NEXTIF field yourself to see the effect it has.

            • #1151619

              Hi Hans,

              Though you didn’t mention the document type for your illustration, I suggest it’s of “labels” type.
              Most likely, the different {NEXTIF} behaviors are related and caused by the different document types (Letters, Email Messages,…etc.)

              Armstrong

            • #1151623

              The “boxes” can represent labels or letters or e-mails – the idea remains the same.

    Viewing 0 reply threads
    Reply To: { NEXTIF Expression1 Operator Expression2 }

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: