Conditional Merge Problem

T

Tom Bean

I am trying to create a document containing up to 30 items in a bulleted
list based on the value of MERGEFIELDs corresponding to each item but am
having problems getting the merge to work correctly.

An example of the list in my current document is:

{ IF { MERGEFIELD Field1 } <> "" "§ Value of Field1 is { MERGEFIELD
Field1 }<Enter>
" }{ IF { MERGEFIELD Field2 } <> "" "§ Text for Field2<Enter>
" }{ IF { MERGEFIELD Field3 } <> "" "§ Text for Field3<Enter>
" }{ IF { MERGEFIELD Field4 } <> "" "§ Value of Field4 is { MERGEFIELD
Field4 }<Enter>
" }<Enter>

where <Enter> indicates where the 'Enter' key is pressed resulting in a
paragraph mark.

I want the document merged using the above example to look like:

§ Value of Field1 is Value1
§ Text for Field2
§ Value of Field4 is Value4

where the data source has "Value1", "Y", "" and "Value4" in Field1, Field2,
Field3 and Field4 columns.

The first problem I encountered was with Bullets showing a blank line if the
condition was not True, hence the square symbol at the beginning of the
text.

After replacing Bullets with the square symbol, everything appeared to work
when all the merge fields had non-empty values. When the value for Field3
was empty, as in the above example, neither the line for Field3 or Field4
were displayed. From various data patterns I tried, the output stopped when
the first empty column was encountered.

Thinking the empty columns might be the problem, I tried putting "N" for the
value of the fields I didn't want displayed and changed the IF statement to
IF { MERGEFIELD Field1 } <> "N". Once again this resulted in unexpected
behavior, all the lines were displayed regardless of whether on not they
contained an "N" and after the first "N" was encountered, the values for
subsequent fields was not shown.

Obviously, I'm doing something wrong.

Can someone please tell me how to do this correctly?

Thanks,
Tom
 
G

Graham Mayor

It works for me as you have it written - assuming § is your bullet
character.

{ IF{ Mergefield Field1 } <> "" "§ Value of Field1 is { Mergefield Field1 }
" }{ IF{ Mergefield Field2 } <> "" "§ Text for Field2
" }{ IF{ Mergefield Field3 } <> "" "§ Text for Field3
" }{ IF{ Mergefield Field4} <> "" "§ Text for Field4 is { Mergefield
Field4 }
" }

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Tom Bean

Graham,

Everything is working fine now. All I did was close the document and the
data source and reopen them and everything worked. It seems like Word
wasn't seeing changes in the data source or got in some state where it
didn't work and reloading it fixed the problems. Is that normal?

Thanks,
Tom
 
G

Graham Mayor

You shouldn't have to re-attach the data file following changes, but you do
have to save the changes! Still as long as it works ....... :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top