time in Word 2003, I'm not sure how I would nest if...then statements
using a 'word field' from the mail merge toolbar. Can you put me on the
right track here?
Since you're probably going to be doing a lot with fields, it's probably
easiest to use the keyboard shortcuts for dealing with fields and avoid the
user interface.
e.g. suppose you need an IF field like
{ IF "{ MERGEFIELD mymergefield }" = "ABC" "{ REF mybookmark1 }" "{ REF
mybookmark2 }" }
then you can use ctrl-F9 to insert each pair of the special field code
braces {}, and type everything else in the usual way on the keyboard.
e.g. you might do
a. ctrl-F9 to give you { }
b. click in the middle of { } and type IF "" = "ABC" "" "" to give you
{ IF "" = "ABC" "" "" }
c. click between each pair of "" in turn press ctrl-F9 to give you
{ IF "{ }" = "ABC" "{ }" "{ }" }
d. click in the first empty { } and type MERGEFIELD mymergefield to give
you
{ IF "{ MERGEFIELD mymergefield }" = "ABC" "{ }" "{ }" }
and so on...
alt-F9 lets you toggle between field codes/field results view (but sometimes
it is more useful to select a single field, then right-click and toggle that
code). select a field then F9 to updte its result, and so on.
Incidentally, many of the "" in my example are probably "redundant", e.g.
the above would probably work just as well using
{ IF { MERGEFIELD mymergefield } = "ABC" { REF mybookmark1 } { REF
mybookmark2 } }
but I tend to "program defensively" and use the quotes that the MS
documentation sometimes suggests should be there, and use the spacing that
Word uses when you insert fields via the U.I. One expception is that if you
use EQ fields, any spaces before the closing } will probably be used in the
result, not ignored.
You need quotes round merge field names if they contain spaces (and perhaps
other characters that might cause ambiguities), e.g.
{ MERGEFIELD "my merge field" }
Make sure they are "straight quotes" not "curly quotes."
using a 'word field' from the mail merge toolbar
if you need to use "intermediate results" you can use SET fields to set the
values of "bookmarks" and REF fields to reference them. This can be slightly
confusing because you can set a bookmark in Word in at least two ways:
a. select a piece of text and use Insert|Bookmark to insert a named
bookmark, e.g. "mybookmark"
b. use a set field, e.g. { SET mybookmark "some text" }
Either way, you can reference the value of the bookmark using
{ REF mybookmark }
or in most cases just
{ mybookmark }
if Customer = 'Acme' then
if Quantity > 100 then
return 'Acme bulk purchase'
else
return 'Acme purchase'
end if
else
if Quantity > 50 then
return 'bulk purchase'
else
return 'purchase
end if
end if
The following may be OK:
{ IF "{ MERGEFIELD Customer }" = "Acme"
"{ IF { MERGEFIELD Quantity } > 100
"Acme bulk purchase"
"Acme purchase" }"
"{ IF { MERGEFIELD Quantity } > 50
"bulk purchase"
"purchase" }" }
(You don't have to break the IF statement into lines as I have done - it can
all be on one line)
However, to ensure that the numeric comparisons are performed correctly you
might use something like
{ IF "{ MERGEFIELD Customer }" = "Acme"
"{ IF { ={ MERGEFIELD Quantity }-100 } > 0
"Acme bulk purchase"
"Acme purchase" }"
"{ IF { = MERGEFIELD Quantity }-50 } > 0
"bulk purchase"
"purchase" }" }"
(but I haven't tested that exact syntax so don't take my word for it!)
Peter Jamieson