Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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. |
#6
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Conditional Mail Merge Help | Mailmerge | |||
Word 2K: Conditional statements (if...then...else) in Merge files | Mailmerge | |||
complex conditional merge | Mailmerge | |||
how can I merge print and keep the conditional formatting | Mailmerge | |||
Conditional mail merge | Mailmerge |