View Single Post
  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Jesse Aufiero Jesse Aufiero is offline
external usenet poster
 
Posts: 3
Default how smart can a word 2003 mail merge letter be?

perfect! this really makes me think i can move forward with the migration
into word.

I wonder when it would be smarter to use bookmarks isntead of literal text.
Your examples show both ways. Do you have a theory on when it's better to
use one than the other?... Do you only bookmark portions of the doc that
are actually part of the end result, or are there times when you stash aside
bookmarked text, for use only by word if...then fields? These are things I
guess i'll come to figure out as i get further into the migration.

I like how you can highlight all merge fields with the click of one button.
Is there a way to easily highlight all word and formula fields too? How
about bookmarks?


"Peter Jamieson" wrote in message
...
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

"Jesse Aufiero" wrote in message
...
Peter,

Thank you for such a comprehensive answer. After spending a fair amount
of 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? Would it involve bookmarking the results of a given
if...then somehow?

Suppose I have two columns in my sql view that are accessible to the mail
merge: Customer and Quantity. How would I accomplish the following in
Word:

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


"Peter Jamieson" wrote in message
...
I can't point you to good examples of complex merges and I'm not really
sure it would help you if I could. Of course Word can do quite complex
merges, but the field language in particular is not well-specified, can
be unpredictable, and making the transition from one version of Word to
the next can be problematic.

To cover some of the specific points you raise...

My templates pull fields from a sql server view into a form letter via
a stored procedure in sql server. there are many if...then conditions,
including nested if...thens throughout the stored procedure code.

In Word 2003 you'll probably have difficulty even setting up a SQL
Server stored procedure as a data source. As far as I know you can only
do it successfully when the procedure has a single statement that
returns rows. Otherwise the procedure returns multiple result sets that
Word does not process correctly.

here, but rather a real world example of a complex mail merge letter
with formulas,

The only formulas in the field language are numeric formulas, although
you can do date manipulation with them and use other tricks. But there
are no text functions such as left, right, mid etc. in the field
language. You can obvioulsy do stuff in the data source, and you can use
the Word Mailmerge events to do per-record processing.

formatting, and if...then logic.

You can out what formatting facilities exist in Word Help. You can
usually translate if...then...else logic into Word IF fields - sometimes
using = fields to test conditions can help. There is a limit of 20
levels of nesting (personally, I would avoid trying to go even close to
that). IF fields can suffer from problems related to the execution
sequence of nested fields (try using SEQ fields in IF fields, for
example)

I'm just trying to gauge if word is robust enough to handle my
templates.

You must have a pretty good reason to move away from an established
solution, but if I were in your shoes, I'd start with the thing I
considered my most complex application, start modelling it in Word, and
see how it went. Then test, test, test.

Peter Jamieson



"Jesse Aufiero" wrote in message
...
I'm considering migrating some very complex templates from my own
proprietary application into word 2003. My templates pull fields from
a sql server view into a form letter via a stored procedure in sql
server. there are many if...then conditions, including nested
if...thens throughout the stored procedure code.

Before I begin to attempt this migration into a word 2003 mail merge
template, is there a good resource I can turn to to see just what word
2003's letter mail merge is capable of? I'm not looking for a tutorial
here, but rather a real world example of a complex mail merge letter
with formulas, formatting, and if...then logic. I'm just trying to
gauge if word is robust enough to handle my templates.

Any advise would be greatly appreciated.

Thanks!