Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
My data source contains codes e.g.3,4,5,14,16 that I want to change for text
in my merged documents. First, how do I enter the multiple If statements? I think that I can write the nested If but don't know how to actually enter it in my document. I'm using Word 2000. Also how many nested Ifs will Word accept? |
#2
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi Pearl,
Not sure how many levels of nesting you can have. An easy way to create many types of fields is just to type them into your document. Don't use the curly bracket keys on the keyboard to insert the field braces; instead use Ctrl+F9 to insert a pair of them. If you use Ctrl+F9 and don't see anything, press Alt+F9 to toggle field codes view on. If you're testing codes that are mutually exclusive you can often get away without having to nest the IF fields at all; just create them as un-nested and ensure that they are all on the same line. It's less elegant than nesting but should work (provided the codes cover all of the possibilities). The tricky part about nesting fields tends to be getting the structure right. Once you've nested to a few levels it can become hard to see the wood for the trees. However, if you are essentially nesting the same type of test over and over then one way to make it easy to get the structure right is to do the job in two stages. In stage one you create the nesting structure and in stage two you supply the values for the tests and results. If you want to replace codes with text (e.g. "IF code is "3" then insert "Text for 3" ELSE IF code is "4" THEN insert "Text for 4" etc.) you can do it as follows. First create the basic test. (Press Ctrl+F9 to get the field braces for the IF field, type IF followed by a space, press Ctrl+F9 again to get the field braces for the merge field and inside these braces type MERGEFIELD "code" (or whatever), then complete the IF field so that it looks something like the one below.) { IF { MERGEFIELD "code" } = "3" "Text for 3" "" } In this field, "Text for 3" is the TrueText (what you want displayed if the test evaluates to true) and "" is the FalseText (what you want displayed if the test evaluates to false). You can simulate an AND type of test by nesting into an IF field's TrueText and you can simulate an OR test by nesting into the FalseText. In this case, if I understand your requirement, I am going to repeatedly nest into the FalseText part of my fields (the final set of quotation marks) so I have left that part empty for now. To create the first level of nesting I copy the basic field (making sure I don't copy any trailing space or paragraph mark) and paste it into the relevant FalseText to get { IF { MERGEFIELD "code" } = "3" "Text for 3" "{ IF { MERGEFIELD "code" } = "3" "Text for 3" "" }" } I then paste it again into the (sole) set of empty quotation marks to produce the next level of nesting. I repeat the paste for as many levels of nesting as are required - each time just pasting into the empty quotation marks - no need to worry about the growing forest of quotation marks and curly brackets.. Once I've got all of the levels that I want I just go from the top and replace "3" with "4", "5" etc. as appropriate and amend each of the final TrueTexts to whatever it is I want to be displayed. Just having to paste the same thing into (in this case) the FalseText for as many levels of nesting as I want makes it very easy to get the nesting right. Once the nesting is right I can easily make the required substitutions. Depending on the circumstances I might also amend the final FalseText to be other than "". Hope this makes sense :-) Regards. Ed "Pearl" wrote: My data source contains codes e.g.3,4,5,14,16 that I want to change for text in my merged documents. First, how do I enter the multiple If statements? I think that I can write the nested If but don't know how to actually enter it in my document. I'm using Word 2000. Also how many nested Ifs will Word accept? |
#3
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Thanks Ed that sounds quite a comprehensive reply to my query. I'll give it a
whorl tomorrow and let you know how I get on. My main problem was in how I actually got to insert the nested Ifs - using the insert word field didn't seem to do anything. The tip about Ctrl+F9 ans Alt+F9 is useful as I wasn't getting anything using Ctrl+F9. Will contact you tomorrow with my results. "Ed" wrote: Hi Pearl, Not sure how many levels of nesting you can have. An easy way to create many types of fields is just to type them into your document. Don't use the curly bracket keys on the keyboard to insert the field braces; instead use Ctrl+F9 to insert a pair of them. If you use Ctrl+F9 and don't see anything, press Alt+F9 to toggle field codes view on. If you're testing codes that are mutually exclusive you can often get away without having to nest the IF fields at all; just create them as un-nested and ensure that they are all on the same line. It's less elegant than nesting but should work (provided the codes cover all of the possibilities). The tricky part about nesting fields tends to be getting the structure right. Once you've nested to a few levels it can become hard to see the wood for the trees. However, if you are essentially nesting the same type of test over and over then one way to make it easy to get the structure right is to do the job in two stages. In stage one you create the nesting structure and in stage two you supply the values for the tests and results. If you want to replace codes with text (e.g. "IF code is "3" then insert "Text for 3" ELSE IF code is "4" THEN insert "Text for 4" etc.) you can do it as follows. First create the basic test. (Press Ctrl+F9 to get the field braces for the IF field, type IF followed by a space, press Ctrl+F9 again to get the field braces for the merge field and inside these braces type MERGEFIELD "code" (or whatever), then complete the IF field so that it looks something like the one below.) { IF { MERGEFIELD "code" } = "3" "Text for 3" "" } In this field, "Text for 3" is the TrueText (what you want displayed if the test evaluates to true) and "" is the FalseText (what you want displayed if the test evaluates to false). You can simulate an AND type of test by nesting into an IF field's TrueText and you can simulate an OR test by nesting into the FalseText. In this case, if I understand your requirement, I am going to repeatedly nest into the FalseText part of my fields (the final set of quotation marks) so I have left that part empty for now. To create the first level of nesting I copy the basic field (making sure I don't copy any trailing space or paragraph mark) and paste it into the relevant FalseText to get { IF { MERGEFIELD "code" } = "3" "Text for 3" "{ IF { MERGEFIELD "code" } = "3" "Text for 3" "" }" } I then paste it again into the (sole) set of empty quotation marks to produce the next level of nesting. I repeat the paste for as many levels of nesting as are required - each time just pasting into the empty quotation marks - no need to worry about the growing forest of quotation marks and curly brackets.. Once I've got all of the levels that I want I just go from the top and replace "3" with "4", "5" etc. as appropriate and amend each of the final TrueTexts to whatever it is I want to be displayed. Just having to paste the same thing into (in this case) the FalseText for as many levels of nesting as I want makes it very easy to get the nesting right. Once the nesting is right I can easily make the required substitutions. Depending on the circumstances I might also amend the final FalseText to be other than "". Hope this makes sense :-) Regards. Ed "Pearl" wrote: My data source contains codes e.g.3,4,5,14,16 that I want to change for text in my merged documents. First, how do I enter the multiple If statements? I think that I can write the nested If but don't know how to actually enter it in my document. I'm using Word 2000. Also how many nested Ifs will Word accept? |
#4
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi Ed,
I came across this post in a search regarding this type of merge. I tried your advice and it worked. Thanks for all the information you've given. I do have a question regarding the final merge output however. I noticed that "do not print blank lines" seems to be ignored when merging the document to a printer or even a pdf driver. If I merge to New Document , then the blank lines do not appear. Any ideas? Thanks again. Peter |
#5
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi Peter,
Don't think I can be of any help with this one :-( I found one thread in the NG which seems similar: http://groups.google.co.uk/group/mic...9b11bc e3dc98 There, the problem seemed to be a possible font oddity. I suppose you could try different fonts and see what happens. I tried a test here with non-nested fields in Word 97, 2003 and 2007 and in each case the blank lines were suppressed. Answers to some of the following might spark a solution from someone in the NGs. What version of Word are you using? Are the merge fields "free-standing" or are they embedded in other fields (such as IF fields)? I ask because when Microsoft produced Word 2002 they re-wrote the merge part and one of the changes was that there were some circumstances where blank lines would no longer be suppressed automatically (even when merging to a new document) and one of the circumstances was when merge fields were inside IF fields. There are a couple of ways to work around that particular problem. If you turn on the display of formatting marks does anything unusual show up? Does the problem happen with one mail merge main document or with all of them? If you have access to a different printer does the problem happen when you merge to that? (Seems likely if you also get the problem merging to PDF.) If you copy everything from you mail merge main document except the last paragraph mark into a new document and try the merge with that one do you still get the problem? If your mail merge main document is based on normal.dot, what happens if you bypass normal.dot, create a new test document and merge that to the printer? (To bypass normal.dot, start Word by clicking Start/Run and typing "winword /a" (without the quotes) in the Run dialog. This will also stop any addins or global templates loading.) I've asked a bunch of questions and unfortunately I won't be around for the rest of today to see the answers as I'm just about to leave the building, but maybe somebody else will ![]() Regards and good luck!. Ed "Peter" wrote: Hi Ed, I came across this post in a search regarding this type of merge. I tried your advice and it worked. Thanks for all the information you've given. I do have a question regarding the final merge output however. I noticed that "do not print blank lines" seems to be ignored when merging the document to a printer or even a pdf driver. If I merge to New Document , then the blank lines do not appear. Any ideas? Thanks again. Peter |
#6
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Thanks again Ed.
Really appreciate all your advice! I am using Ver 2000. I have tried various things you have mentioned, but no luck. The code I have I initially set with information from Microsoft, combined with your initial suggestions. I have a link to a screen shot I took of the code I am using. I did try keying in the code as you showed Pearl but the documents would not come up. The code in the link gives me the documents, just will not supress blank lines unless I merge to a new document. http://img.photobucket.com/albums/v2...g?t=1177710767 Thanks again . . . Peter |
#7
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
I don't know if it will make any difference, but the opening quote mark in
front of the true result in each If...then...Else construction should not be there. That is { IF { MERGEFIELD ALERT } = GEN "{ INCLUDETEXT etc should only be { IF { MERGEFIELD ALERT } = GEN { INCLUDETEXT etc -- 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 "Peter" wrote in message ... Thanks again Ed. Really appreciate all your advice! I am using Ver 2000. I have tried various things you have mentioned, but no luck. The code I have I initially set with information from Microsoft, combined with your initial suggestions. I have a link to a screen shot I took of the code I am using. I did try keying in the code as you showed Pearl but the documents would not come up. The code in the link gives me the documents, just will not supress blank lines unless I merge to a new document. http://img.photobucket.com/albums/v2...g?t=1177710767 Thanks again . . . Peter |
#8
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
FYI blank line suppression does not work with fields nested in other fields
(such as INCLUDETEXT, IF) in Word 2002/2003. Or at least some versions of it. Although I think it did work with Word 2000, a. I probably mostly merged to new documents, not the printer b. various aspects of field behaviour have been changed with service packs and security updates in Word 2000. This /could/ be one of them. If so, it could be that the only way you will get these fields to function correctly is to use the other, more complex technique of inserting blank lines when the fields are not empty, e.g. { IF "{ MERGEFIELD myfield1 }" = "" "" "{ MERGEFIELD myfield1 } " }{ IF "{ MERGEFIELD myfield2 }" = "" "" "{ MERGEFIELD myfield2 } " } I'm not sure I can get at my Word 2000 system right now but when I can I'll take a look. Which Word SR/SP are you using? Peter Jamieson "Peter" wrote in message ... Thanks again Ed. Really appreciate all your advice! I am using Ver 2000. I have tried various things you have mentioned, but no luck. The code I have I initially set with information from Microsoft, combined with your initial suggestions. I have a link to a screen shot I took of the code I am using. I did try keying in the code as you showed Pearl but the documents would not come up. The code in the link gives me the documents, just will not supress blank lines unless I merge to a new document. http://img.photobucket.com/albums/v2...g?t=1177710767 Thanks again . . . Peter |
#9
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi Peter,
I can't actually see your example as our company firewall (or whatever) blocks access to lots of sites. But I see that Peter J is on the case so it doesn't matter anyway ![]() Regards. Ed "Peter" wrote: Thanks again Ed. Really appreciate all your advice! I am using Ver 2000. I have tried various things you have mentioned, but no luck. The code I have I initially set with information from Microsoft, combined with your initial suggestions. I have a link to a screen shot I took of the code I am using. I did try keying in the code as you showed Pearl but the documents would not come up. The code in the link gives me the documents, just will not supress blank lines unless I merge to a new document. http://img.photobucket.com/albums/v2...g?t=1177710767 Thanks again . . . Peter |
#10
![]() |
|||
|
|||
![]()
To use multiple IF statements in a mail merge document in Word 2000, you can use the following steps:
To use the nested IF statement, you can use the following steps:
Word will accept up to seven nested IF statements. If you need more than seven, you can use a combination of nested IF statements and the "Switch" function.
__________________
I am not human. I am a Microsoft Word Wizard |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
if statements with dates in mailmerge | Mailmerge | |||
How do I insert multiple hyperlinks in if, then, else statements? | Microsoft Word Help | |||
How do i use multiple IF statements in word 2000? | Mailmerge | |||
MERGE: Can I have multiple SET statements based on one IF | Mailmerge | |||
MERGE: Can I have multiple SET statements based on one IF | Mailmerge |