Reply
 
Thread Tools Display Modes
  #1   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?

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!


  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default how smart can a word 2003 mail merge letter be?

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!



  #3   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?

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!





  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default how smart can a word 2003 mail merge letter be?

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!







  #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!











  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default how smart can a word 2003 mail merge letter be?

If you really want to see what can be done with fields, take a look at the
magnus opus by fellow MVP Macropod at:

http://www.wopr.com/cgi-bin/w3t/show...?Number=249902

Here's an example of the sort of thing that he comes up with:

The following compound field will return the scientific notation of any +ve
value between 10^-9 and 10^9:
{QUOTE
{SET a {SourceVal}}
{SET
b{=9-(a10^9)-(a10^8)-(a10^7)-(a10^6)-(a10^5)-(a10^4)-(a10^3)-(a10^2)
-(a10^1)-(a10^0)-(a10^-1)-(a10^-2)-(a10^-3)-(a10^-4)-(a10^-5)-(a10^-
6)-(a10^-7)-(a10^-8)}}
{SET c{=int(a/10^b)+mod(a,10^b)/10^b}}
{c \# 0.00}E{b \# +00;-00}}
where 'SourceVal' is the input, which could be a formula taking its input
from two formfields. You can extend the range easily enough by adding more
terms.



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Jesse Aufiero" wrote in message
...
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!











  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default how smart can a word 2003 mail merge letter be?

Do you have a theory

Not really...

I wonder when it would be smarter to use bookmarks isntead of literal
text.


Broadly speaking it's similar to using variables v. literal values or "named
constants" in a procedural language such as VB or C, but the field language
sometimes behaves a bit more like a traditional macro language designed for
text replacement (cf. MACRO-11 if that rings any bells). e.g. you might use
a bookmark, document property or document variable because you want to
define a literal text once and use it many times. As for marking text via
bookmarks versus using SET fields to define bookmarks, I can't remember
anything off the top of my head where the former can do something that the
latter can't, and the SET approach has the advantage that the SET value
doen't appear in the output.

More specifically, it can be helpful to use SET and bookmarks when you want
to use "difficult" characters such as ", e.g.

{ SET q { quote 34 } }

defines a bookmark containing a double-quote character that lets you do
stuff such as

{ IF { MERGEFIELD myfield } = "something" "blah{q}blah" "" }

You could probably use { QUOTE 34 } instead but if you need it a lot, { q }
is a lot shorter!

Something to be careful about when designing documents that use fields is
that Word automatically updates some types of field when it opens a document
but not others. For example, it doesn't automatically update IF fields. So
you can have field logic that looks fine, and functions fine as long as the
user selects all the fields and updates them, but which displays
inconsistent values from the point where the document is opened to the point
where all the fields are updated. Since I mainly use fields in merges, this
isn't a problem I generally encounter because Word updates (almost)
everything during a merge.

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?


As far as I know, you get the options you see in Tools|Options|View and
that's about it - you could make some macros to alter those options in
various ways and attach the macros to some toolbar buttons or keystrokes
(I'd probably put them on the MailMerge toolbar if I used them enough) but
that's about it. You might also find the option Word
Tools|Options|Print|"Include with document"|"Field codes" useful during
development.

Peter Jamieson



"Jesse Aufiero" wrote in message
...
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!











Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word should catalog misspelled words to study. rndthought Microsoft Word Help 39 May 21st 23 02:47 AM
Word 97 in Windows XP to maintain formatting Charlie''s Word VBA questions Microsoft Word Help 22 May 20th 23 08:51 PM
How to put graphics on envelopes? Steve Koenig Microsoft Word Help 21 April 29th 23 02:47 AM
How do I mail merge to EMAIL from MS Word AND add a pdf attachment Lily@Insight Mailmerge 24 January 15th 07 09:33 PM
Specific Email Merge w/ Specific Attachements Mark B Mailmerge 9 February 21st 05 05:10 AM


All times are GMT +1. The time now is 08:26 AM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"