+ Reply to Thread
Results 1 to 6 of 6

MERGEFIELD nested IF conditions

  1. #1
    Forum Contributor
    Join Date
    10-30-2014
    Location
    England
    MS-Off Ver
    2007 / 365
    Posts
    279

    MERGEFIELD nested IF conditions

    I have 2 Code fields in a Mail Merge doc. They are on the same line, and between them I would like a forward slash. However, if either field is blank I would not like the forward slash to display.

    So 3 possible outcomes:

    • Code_1 / Code2
    • Code_1
    • Code_2

    Currently I have the following { IF { MERGEFIELD Code_1 } = "" "" { IF { MERGEFIELD Code_2 } = "" "" "/" } }. However, this doesn't seem to work, I just get MERGEFIELD displayed. I am adding a proper IF rule to create the field, then I am editing the expression within the Edit dialog. I have found several topics on this, and the only difference I could see is that one solution has additional quotes around the second IF expression, but I couldn't get that to work either.

    Any help to adjust this to work would be appreciated, or perhaps I'm doing it completely wrong and there a much better way to achieve the desired results ?
    Last edited by EchoPassenger; 04-03-2023 at 03:49 PM.

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: MERGEFIELD nested IF conditions

    From your description, it seems that the MERGEFIELD code is not being evaluated and is instead being displayed as text.

    One possible reason for this could be that the field code is not being updated. To update the field codes, you can press F9 or right-click on the field and select "Update Field."

    Regarding the syntax of your IF statement, here's an example of what it should look like:

    Please Login or Register  to view this content.
    Notice that the second IF statement is enclosed in quotes. This is because it is being used as the "false" value for the first IF statement.

    If the above solution does not work, you may want to try replacing the curly braces with chevrons, as some versions of Word require this. Here's an example:

    Please Login or Register  to view this content.
    or maybe
    Please Login or Register  to view this content.
    This statement checks if Code_1 is empty, and if it is, it displays Code_2. If Code_2 is empty, it displays Code_1. If both fields have values, it displays both fields separated by a forward slash.

    Make sure to include the curly braces {} around each field and the entire statement.
    Last edited by sandy666; 04-03-2023 at 03:05 PM.

  3. #3
    Forum Contributor
    Join Date
    10-30-2014
    Location
    England
    MS-Off Ver
    2007 / 365
    Posts
    279

    Re: MERGEFIELD nested IF conditions

    Thanks.

    Your first example is the other syntax I had tried. I've now copied all of your examples into the Edit field dialog, but still only MERGEFIELD is displayed, or > is displayed for the chervon example.

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: MERGEFIELD nested IF conditions

    Please Login or Register  to view this content.
    This statement checks if Code_1 is empty, and if it is, it displays nothing. If Code_1 is not empty and Code_2 is not empty, it displays a forward slash. If Code_2 is empty, it displays nothing.
    Make sure to include the curly braces {} around each field and the entire statement.
    I hope this solution works for you

  5. #5
    Forum Contributor
    Join Date
    10-30-2014
    Location
    England
    MS-Off Ver
    2007 / 365
    Posts
    279

    Re: MERGEFIELD nested IF conditions

    Thanks again for your effort, but I've cracked it.

    I didn't notice before, but when viewing the Field Codes the curly braces within the expression weren't as dark as the pair wrapping it, so clearly they weren't being parsed as expected.

    I found that I had to build the full expression up in stages...

    Add a single IF rule.
    Toggle the Field Codes.
    Click inside the FALSE argument.
    Add another single IF rule in this position.
    Highlight the result from the second IF rule, and Toggle the Field Code.
    Then just finally clean up the required TRUE and FALSE values.

    Madness how fiddly that is!
    Last edited by EchoPassenger; 04-03-2023 at 03:48 PM.

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: MERGEFIELD nested IF conditions

    Good you solved it
    Have a nice day

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 03-17-2017, 03:49 PM
  2. [SOLVED] Find and replace mergefield in several files macro
    By Marco-Kun in forum Word Programming / VBA / Macros
    Replies: 16
    Last Post: 11-22-2012, 04:31 PM
  3. Find and replace mergefield in several files
    By Marco-Kun in forum Word Formatting & General
    Replies: 2
    Last Post: 11-15-2012, 05:05 AM
  4. Replies: 3
    Last Post: 05-29-2012, 07:54 AM
  5. removing a added .0 after a mergefield from excel sheet
    By antiprojektz in forum Word Formatting & General
    Replies: 1
    Last Post: 01-09-2010, 05:13 PM
  6. Mergefield character limit
    By Stupot101 in forum Excel General
    Replies: 1
    Last Post: 11-25-2008, 06:11 AM
  7. more than 7 nested IF conditions?
    By krayziez in forum Excel General
    Replies: 5
    Last Post: 06-19-2008, 01:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1