Reply
 
Thread Tools Display Modes
  #1   Report Post  
William Gieske
 
Posts: n/a
Default How do I do a conditional merge?

I have an Excel "database" consisting of high school classmates. Pertinent
fields for this question are FirstName, LastName and MarriedName. LastName is
the last name of the classmate when they were in high school. If they are
married, it's their maiden name.

For mailing purposes, if the classmate is married, the name line should
read: FirstName (LastName) MarriedName. If the classmate is not married, then
it should read FirstName LastName. And of course, for the men, it's always
FirstName LastName.

To accomplish this, I want to use an If field field code. Help says the
format is:
{ IF Expression1 Operator Expression2 TrueText FalseText }
That translates to { IF MarriedName = "" True False }

This obviously does not work. I think I need { MergeField MarriedName }
instead of just the field name. But that does not seem to get the job done.

Ultimately, the statement needs to print either of the above two name line
formats, depending on whether there is a name in the MarriedName column in
the spreadsheet.

I've tried various combinations from the spartan examples given in the help
file, but have yet to get this to work.

Any help would be appreciated.

  #2   Report Post  
Tywardreath
 
Posts: n/a
Default

I've taken a slightly different approach using Excel.

Col A = FirstName
Col B = LastName
Col C = a formula similar to this =IF(D2="","N","Y")
Col D = SchoolName

What it does is if there is a SchoolName, then it flags that row as a Y. If
there is no SchoolName (eg male, or not married), then it flags that row as
an N.

Okay - back to Word.

In the mail merge I have a field that looks like this:
{ IF { MERGEFIELD Married } = "Y" " { MERGEFIELD "SchoolName" } " " {
MERGEFIELD "LastName" } " }

This will produce their name when they went or school, or if it is
different, their married name.

Hope that helps.

Cheers, Tywardreath
  #3   Report Post  
Tywardreath
 
Posts: n/a
Default

Oppsie made a rather major typo...

In the mail merge I have a field that looks like this:
{ IF { MERGEFIELD Married } = "Y" " { MERGEFIELD "SchoolName" } " " {
MERGEFIELD "LastName" } " }


This will produce their surname when they went to school.
  #4   Report Post  
Doug Robbins
 
Posts: n/a
Default

{ IF { MERGEFIELD MarriedName } "" "({ MERGEFIELD LastName }) { MERGEFIED
MarriedName }" "{
MERGEFIELD LastName }" }


--
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
"William Gieske" William wrote in message
news
I have an Excel "database" consisting of high school classmates. Pertinent
fields for this question are FirstName, LastName and MarriedName. LastName
is
the last name of the classmate when they were in high school. If they are
married, it's their maiden name.

For mailing purposes, if the classmate is married, the name line should
read: FirstName (LastName) MarriedName. If the classmate is not married,
then
it should read FirstName LastName. And of course, for the men, it's always
FirstName LastName.

To accomplish this, I want to use an If field field code. Help says the
format is:
{ IF Expression1 Operator Expression2 TrueText FalseText }
That translates to { IF MarriedName = "" True False }

This obviously does not work. I think I need { MergeField MarriedName }
instead of just the field name. But that does not seem to get the job
done.

Ultimately, the statement needs to print either of the above two name line
formats, depending on whether there is a name in the MarriedName column in
the spreadsheet.

I've tried various combinations from the spartan examples given in the
help
file, but have yet to get this to work.

Any help would be appreciated.



  #5   Report Post  
Tywardreath
 
Posts: n/a
Default

That's great to know Doug

.... and I was having so much fun in excel hehe




  #6   Report Post  
William Gieske
 
Posts: n/a
Default

The construct below does not work as is. The value derived is the word
MERGEFIELD. It appears that expression1 must be enclosed in quotes in order
for the condition to be evaluated. The resulting statement becomes { IF "{
MERGEFIELD MarriedName }" "" "Yes" "No" }.

The condition test always returns true, however, regardless of whether the
MarriedName column contains a value. For debugging purposes, I substituted
"Yes" and "No" for the true or false values.

If I replace "Yes" with the construct as you noted it for the TrueText, the
value returned is ({ MERGEFIELD LastName }) { MERGEFIED MarriedName }. These
do not expand to the values in the respective Excel columns.

Tywardreath's example uses quotes around the TrueText and FalseText
constructs, which, when used, alter the value returned. However, even then
the value is not the value from Excel.

I will solve this by doing the test in Excel, as suggested by Tywardreath.
That works if I use the address block instead of a custom built address
construct and map the column accordingly. I loose the ability to print the
maiden name in parenthesis where warranted, but at least I can get a valid
address.

Thanks for your help.


"Doug Robbins" wrote:

{ IF { MERGEFIELD MarriedName } "" "({ MERGEFIELD LastName }) { MERGEFIED
MarriedName }" "{
MERGEFIELD LastName }" }


  #7   Report Post  
William Gieske
 
Posts: n/a
Default

The suggestion generate a column in Excel is a good alternative solution.
While waiting for replies, I did something similar in Excel. I created a new
column, named PrintName, and populated it with the LastName if no MarriedName
existed, and MarriedName where it did. I've given up on including the maiden
name in parenthesis, which will be OK. Rather than create a custom address
block, I'll use the standard address block and map the fields accordingly. At
least this will get the job done.

There's more detail in my replay to Doug Robbins.

I've programmed in various languages over the years, but don't recall
anything that used constructs as optuse as the merge fields. As essoteric as
Korn Shell was (Unix shell), it was well documented and thus could be used
productively.

Thanks for your help.


"Tywardreath" wrote:

I've taken a slightly different approach using Excel.

Col A = FirstName
Col B = LastName
Col C = a formula similar to this =IF(D2="","N","Y")
Col D = SchoolName

What it does is if there is a SchoolName, then it flags that row as a Y. If
there is no SchoolName (eg male, or not married), then it flags that row as
an N.

Okay - back to Word.

In the mail merge I have a field that looks like this:
{ IF { MERGEFIELD Married } = "Y" " { MERGEFIELD "SchoolName" } " " {
MERGEFIELD "LastName" } " }

This will produce their name when they went or school, or if it is
different, their married name.

Hope that helps.

Cheers, Tywardreath

  #8   Report Post  
Graham Mayor
 
Posts: n/a
Default

The correct syntax is
{IF{Mergefield MarriedName} "" "Yes" "No"}
The field boundaries {} are inserted with CTRL+F9, not typed from the
keyboard
The quotes around the results are unnecessary when the results are the
contents of the fields, but I strongly urge you to retain them as they may
debugging much simpler as shown in Doug's earlier post which had the full
required field codes.

{ IF { MERGEFIELD MarriedName } "" "({ MERGEFIELD LastName }) {
MERGEFIELD
MarriedName }" "{MERGEFIELD LastName }" }


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


William Gieske wrote:
The construct below does not work as is. The value derived is the word
MERGEFIELD. It appears that expression1 must be enclosed in quotes in
order for the condition to be evaluated. The resulting statement
becomes { IF "{ MERGEFIELD MarriedName }" "" "Yes" "No" }.

The condition test always returns true, however, regardless of
whether the MarriedName column contains a value. For debugging
purposes, I substituted "Yes" and "No" for the true or false values.

If I replace "Yes" with the construct as you noted it for the
TrueText, the value returned is ({ MERGEFIELD LastName }) { MERGEFIED
MarriedName }. These do not expand to the values in the respective
Excel columns.

Tywardreath's example uses quotes around the TrueText and FalseText
constructs, which, when used, alter the value returned. However, even
then the value is not the value from Excel.

I will solve this by doing the test in Excel, as suggested by
Tywardreath. That works if I use the address block instead of a
custom built address construct and map the column accordingly. I
loose the ability to print the maiden name in parenthesis where
warranted, but at least I can get a valid address.

Thanks for your help.


"Doug Robbins" wrote:

{ IF { MERGEFIELD MarriedName } "" "({ MERGEFIELD LastName }) {
MERGEFIED MarriedName }" "{
MERGEFIELD LastName }" }



  #9   Report Post  
William Gieske
 
Posts: n/a
Default

Thank you. Correct syntax makes all the difference, as with any programming
language. The help page for the IF field code did not mention that the field
boundaries are inserted with Ctrl+F9. That would have helped immensely! I
guess that's the danger of jumping into the middle of something via a help
page, but not knowing the basics, like syntax. Knowing now that this was the
issue, I found a help topic that explains that. At times like these, I find
myself longing for a manual. But no manual will tell me how to replace the
hair I've pulled out trying to get this to work. Again, thanks.

"Graham Mayor" wrote:

The correct syntax is
{IF{Mergefield MarriedName} "" "Yes" "No"}
The field boundaries {} are inserted with CTRL+F9, not typed from the
keyboard
The quotes around the results are unnecessary when the results are the
contents of the fields, but I strongly urge you to retain them as they may
debugging much simpler as shown in Doug's earlier post which had the full
required field codes.

{ IF { MERGEFIELD MarriedName } "" "({ MERGEFIELD LastName }) {
MERGEFIELD
MarriedName }" "{MERGEFIELD LastName }" }


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


William Gieske wrote:
The construct below does not work as is. The value derived is the word
MERGEFIELD. It appears that expression1 must be enclosed in quotes in
order for the condition to be evaluated. The resulting statement
becomes { IF "{ MERGEFIELD MarriedName }" "" "Yes" "No" }.

The condition test always returns true, however, regardless of
whether the MarriedName column contains a value. For debugging
purposes, I substituted "Yes" and "No" for the true or false values.

If I replace "Yes" with the construct as you noted it for the
TrueText, the value returned is ({ MERGEFIELD LastName }) { MERGEFIED
MarriedName }. These do not expand to the values in the respective
Excel columns.

Tywardreath's example uses quotes around the TrueText and FalseText
constructs, which, when used, alter the value returned. However, even
then the value is not the value from Excel.

I will solve this by doing the test in Excel, as suggested by
Tywardreath. That works if I use the address block instead of a
custom built address construct and map the column accordingly. I
loose the ability to print the maiden name in parenthesis where
warranted, but at least I can get a valid address.

Thanks for your help.


"Doug Robbins" wrote:

{ IF { MERGEFIELD MarriedName } "" "({ MERGEFIELD LastName }) {
MERGEFIED MarriedName }" "{
MERGEFIELD LastName }" }




  #10   Report Post  
Graham Mayor
 
Posts: n/a
Default

It is much simpler to build such constructions manually, but you could have
inserted the fields into the conditional field from the toolbar
(http://www.gmayor.com/mail_merge_lab...th_word_xp.htm ) whereupon it
would have looked more like

{ IF MarriedName "" "(LastName) {MarriedName"
"LastName" }

Working with fields you need to imprint the following commands on your
consciousness:

CTRL+F9 - insert field boundary
ALT+F9 - toggle field display
F9 - update field.


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


William Gieske wrote:
Thank you. Correct syntax makes all the difference, as with any
programming language. The help page for the IF field code did not
mention that the field boundaries are inserted with Ctrl+F9. That
would have helped immensely! I guess that's the danger of jumping
into the middle of something via a help page, but not knowing the
basics, like syntax. Knowing now that this was the issue, I found a
help topic that explains that. At times like these, I find myself
longing for a manual. But no manual will tell me how to replace the
hair I've pulled out trying to get this to work. Again, thanks.

"Graham Mayor" wrote:

The correct syntax is
{IF{Mergefield MarriedName} "" "Yes" "No"}
The field boundaries {} are inserted with CTRL+F9, not typed from the
keyboard
The quotes around the results are unnecessary when the results are
the contents of the fields, but I strongly urge you to retain them
as they may debugging much simpler as shown in Doug's earlier post
which had the full required field codes.

{ IF { MERGEFIELD MarriedName } "" "({ MERGEFIELD LastName }) {
MERGEFIELD
MarriedName }" "{MERGEFIELD LastName }" }


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


William Gieske wrote:
The construct below does not work as is. The value derived is the
word MERGEFIELD. It appears that expression1 must be enclosed in
quotes in order for the condition to be evaluated. The resulting
statement becomes { IF "{ MERGEFIELD MarriedName }" "" "Yes"
"No" }.

The condition test always returns true, however, regardless of
whether the MarriedName column contains a value. For debugging
purposes, I substituted "Yes" and "No" for the true or false values.

If I replace "Yes" with the construct as you noted it for the
TrueText, the value returned is ({ MERGEFIELD LastName }) {
MERGEFIED MarriedName }. These do not expand to the values in the
respective Excel columns.

Tywardreath's example uses quotes around the TrueText and FalseText
constructs, which, when used, alter the value returned. However,
even then the value is not the value from Excel.

I will solve this by doing the test in Excel, as suggested by
Tywardreath. That works if I use the address block instead of a
custom built address construct and map the column accordingly. I
loose the ability to print the maiden name in parenthesis where
warranted, but at least I can get a valid address.

Thanks for your help.


"Doug Robbins" wrote:

{ IF { MERGEFIELD MarriedName } "" "({ MERGEFIELD LastName }) {
MERGEFIED MarriedName }" "{
MERGEFIELD LastName }" }



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
Conditional Mail Merge Help Susan Ramlet Mailmerge 0 August 22nd 05 06:26 PM
Word 2K: Conditional statements (if...then...else) in Merge files leftnotracks Mailmerge 0 June 16th 05 10:18 PM
complex conditional merge Walter Mailmerge 0 January 9th 05 12:49 AM
how can I merge print and keep the conditional formatting Bob M Mailmerge 1 December 15th 04 02:32 PM
Conditional mail merge Hanif Mailmerge 1 November 26th 04 07:10 PM


All times are GMT +1. The time now is 05:31 AM.

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

About Us

"It's about Microsoft Word"