Inserting IncludeText within an IF fileld

C

chops

I am trying to insert IncludeText within an IF Field statement. e.g IF
postcode has CV* then print text A IF not then print text B. Do i have to
also give the IncludeText text a Bookmark referenece?
 
G

Graham Mayor

If you are inserting alternative bookmarked text items from the same
document then you would use something like

{ INCLUDETEXT "D:\\My Documents\\Word Documents\\Doc1.Docx" { IF{ Ref
Postcode } = "CV*" "Text1" "Text2" }}

Which will insert bookmarked item Text1 if the test is true otherwise Text2
Use a Mergefield instead of the REF field as appropriate.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Pesach Shelnitz

Hi,

You can use one wildcard (*) in the IF field to do this. For example,

{If {Bookmark1} = "CV*" "A" "B"}

Don't type the curly brackets ({}). You create them by selected the text to
be enclosed and pressing Ctrl+F9. Here Bookmark1 points to the postcode.
 
C

chops

Yes thank you. In your statement below i understand that if Bookmark 1 = CV*
then text A is written but if it doesn't = CV* then text B is written.

I am trying to achieve a situation where =CV* text from another document e.g
C:\documents\textA.doc is then written into this space. I am using the
Include text function but it isn't working. My string in the IF field code
box is: IF BM2="CV*" {INCLUDETEXT "C:\documents\textA.doc"} "Error".

I have written many different IncludeText fields in the past and haven't had
any problems but this is a slightly different use of the IF statement in
Fields.

Hope this gives you some better info of what i am trying to achieve.

Thanks
 
C

chops

So are you saying within document Doc1.docx you have two bookmark pieces of
text called "text1" and "text2"?

What if you want different paragraphs of text from different documents? Can
this be done?

Thanks
 
P

Pesach Shelnitz

Hi,

In the IF statement you must enclose each result in quotation marks, and if
you want the result to be text from another document, rather than the whole
document, you should specify a bookmark from the other document, for example,
a bookmark named TextA. The following modified version of your IF field
should work.

{IF {BM2}="CV*" "{INCLUDETEXT "C:\\documents\\textA.doc" TextA}" "Error"}

Be sure to create all the pairs of curly brackets by selecting and pressing
Ctrl+F9.
 
P

Peter Jamieson

Hi,
In the IF statement you must enclose each result in quotation marks, and if
you want the result to be text from another document, rather than the whole
document, you should specify a bookmark from the other document, for example,
a bookmark named TextA. The following modified version of your IF field
should work.

{IF {BM2}="CV*" "{INCLUDETEXT "C:\\documents\\textA.doc" TextA}" "Error"}

Be sure to create all the pairs of curly brackets by selecting and pressing
Ctrl+F9.

FWIW there is slightly more to it than this, e.g.
a. One-off inclusions (e.g. where you execute the { IF } field
manually) should work. But in a mailmerge, the IF field may only be
evaluated once in an output document (i.e. you may have to select the
output document and re-execute the fields). Inverting the nesting so
that you have an IF inside of an INCLUDETEXT, as Graham has suggested,
is sometimes a solution for this problem
b. In the general case it's advisable to surround REF fields by
quotes, e.g.

With
{IF {BM2}="CV*" "{INCLUDETEXT "C:\\documents\\textA.doc" TextA}" "Error"}

If the value of the bookmark BM2 is "mybm" and there happens to be a
bookmark in the document called mybm, instead of comparing
the value of bookmark BM2 with "CV*"
Word will compare
the value of bookmark mybm with "CV*"

If you use
{IF "{BM2}"="CV*" "{INCLUDETEXT "C:\\documents\\textA.doc" TextA}" "Error"}

that particular problem should be avoided.

c. Personally I prefer to surround the "true" and "false" results by
double quotes as you have suggested because
(1) it's a consistent approach that always seems to work and
(2) it's what Microsoft generally seems to have put in their
documentation, i.e. the nearest thing to a "documented syntax" that we have

but that said, it does not appear to be necessary in the cases where a
result consists of a single field, or a single text token.


Peter Jamieson

http://tips.pjmsn.me.uk
 

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