View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default Insert certain paragraphs based on fields in Excel database

Ah, I see. That's more difficult, because it's hard to look at parts of a
string using Word fields. The /simplest/ thing to do in this case is to
separate the codes in Excel (e.g. have four columns and "L" or blank etc.)

In theory you could also have one IF field for every possible combination,
but that's quite a lot of IF fields, e.g.

{ SET L "N" }{ SET C "N" }{ SET W "N" }{ SET G "N" }
{ IF "{ MERGEFIELD letter }" = "L" "{ SET L "Y" }" ""
}{ IF "{ MERGEFIELD letter }" = "LC" "{ SET L "Y" }{ SET C "Y" }" ""
}

etc.


then { IF { L } = "Y" "put your L text here" "" }

and so on.

And that will only work if the sequence of the letters is irrelevant, i.e.
if LCW means use paras L, C, W in that order and LWC means use LWC in that
order, you would have to modifythat.


As long as you know that there can only be four letters and the sequence is
iirelevant you can cut the number of IF fields down by using wild cards,
e.g.

{ IF "{ MERGEFIELD letter }" = "L*" "{ SET L "Y" }" ""
}{ IF "{ MERGEFIELD letter }" = "*L" "{ SET L "Y" }" ""
}{ IF "{ MERGEFIELD letter }" = "?L*" "{ SET L "Y" }" ""
} IF "{ MERGEFIELD letter }" = "??L*" "{ SET L "Y" }" ""
}{ IF "{ MERGEFIELD letter }" = "C*" "{ SET C "Y" }" ""
}

and so on.

if you know that the sequence is always LCWG, i.e. you can have L, LC, CW,
LWG etc. but not CL, you can simplify that a bit:

{ IF "{ MERGEFIELD letter }" = "L*" "{ SET L "Y" }" ""
}{ IF "{ MERGEFIELD letter }" = "C*" "{ SET C "Y" }" ""
}{ IF "{ MERGEFIELD letter }" = "?C*" "{ SET C "Y" }" ""
}{ IF "{ MERGEFIELD letter }" = "W*" "{ SET W "Y" }" ""
}{ IF "{ MERGEFIELD letter }" = "?W*" "{ SET C "Y" }" ""
}

Alternatively, you can create a separate Word document - let's call it
c:\mydocs\paras.doc - containing the three paragraphs and create bookmarks
corresponding to each possible combination of letters. I would use bookmark
names "A", "AL", "AC" etc. where "A" means "none of the letters" because
then you can use

{ INCLUDETEXT "c:\\mydocs\\paras.doc" "A{ MERGEFIELD letter }" }

to include the correct text. If the paragraphs can be in different
seqeunces, you will need to create each sequence of paras. in paras.doc and
assign the appropriate bookmarks to each sequence.

It may be possible to do this a simpler way but my brain's not firing on all
cylinders at the moment...

Peter Jamieson
{ IF "{ MERGEFIELD letter }"
"MarvInBoise" wrote in message
...
Thank you, I played around with it and I think I can get it to work;
however,
it only appears to work if I have one code in the "letter" field. If I
have
LWC in the field, meaning it gets 3 paragraphs, it doesn't seem to work;
if I
only have L or W or C individually, then it works. ??
--
Marv Lusk
Boise Corporation


"Peter Jamieson" wrote:

If your paragraphs are quite simple you should be able to use IF fields,
e.g.

{ IF "{ MERGEFIELD letter }" = "L" "put the text of your liability
paragraph
here" ""
}{ IF "{ MERGEFIELD letter }" = "C" "put the text of your C type
paragraph
here" ""
}

etc.

Use ctrl-F9 to insert each pair of {}, and type everything else in the
usual
way.

Peter Jamieson

"MarvInBoise" wrote in message
...
Need to choose certain paragraphs to be inserted in Word document with
mail
merge to an Excel file; the Excel file "letter" field can contain a
character
defining the paragraph to be inserted, e.g., L=Liability pagragraph;
the
"letter field can contain LCWG; each letter designates a different
paragraph
be inserted.
--
Marv Lusk
Boise Corporation