#1
|
|||
|
|||
and if statement in word mailmerge
Hi,
I am trying to get the mailmerge to look at a mailmerge field and if it displays the words "Continued" I want it to take no action, but if it does not display "Continued" and the page number is an even number I want it to insert a page break. The code below inserts a blank page on every page unless it displays "Continued" which isn't quite correct. {if {MERGEFIELD RunTotal \####,###,##0.00}="Continued" { IF{ =MOD({ PAGE \*Arabic },2)}=0 }"[page break]Intentionally blank page" " " } Any help would be very much appreciated. Thanks, Stephen. |
#2
|
||||
|
||||
Try a field coded as:
{IF{MERGEFIELD RunTotal}= "Continued" {IF{=MOD({PAGE},2)}= 0 "{QUOTE 12}Intentionally blank page"}} Note: the displayed spaces are all required.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hi Paul,
Thank you very much for your reply. Have entered the new code but still doesn't work. I've double checked spaces, brackets etc. are all correct but still no joy. Thanks, Stephen. |
#4
|
||||
|
||||
I suspect the underlying issue is that {MERGEFIELD RunTotal} never outputs "Continued", because the mailmerge process treats the entire column as numeric and anything text is output as 0. You should be able to test that. If I am correct about what's happening and if your data don't include and true 0s or blanks, you could re-code the field as:
{IF{MERGEFIELD RunTotal}= 0 {IF{=MOD({PAGE},2)}= 0 "{QUOTE 12}Intentionally blank page"}}
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Hi Paul,
I have tested and it reads the "Continued" text fine. The code below puts a blank page after every page where "Continued" is not displayed but I need this to only work on even numbered pages where "Continued" is not displayed. Any ideas? I am new to Word if statements but I can feel a resolution is just around the corner! {IF{MERGEFIELD RunTotal}<> "Continued" {IF{=MOD({PAGE},2)}= 0 " " "[page break]Intentionally blank page"}} |
#6
|
||||
|
||||
The problem you're having is probably a result of the way the IF field gets evaluated. Try:
{={=MOD({PAGE},2) \# 0}+{IF{MERGEFIELD RunTotal}= "Continued" 0 1} \# ";;'{QUOTE 12}Intentionally blank page'"}
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Hi Paul,
Tried this and it puts a blank page after every page, in other words every other page is blank regardless of whether "Continued" is on page or whether it is odd or even. Thanks, Stephen. |
#8
|
||||
|
||||
That suggests either:
• some of the braces you're using (i.e. { }) are not field braces. You can't type them or copy/paste them from here - they need to be created in pairs via Ctrl-F9, for example; or • you've messed up the spaces and/or the use of single/double quotes in the field code. Note the use of single quotes for '{QUOTE 12}Intentionally blank page'. PS: I've tested the field code, so I know it does work.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Hi Paul,
I have attached a screenshot of my file. With this code in it puts a blank page after every page regardless of any conditions. Sorry if I am being dense! I need it to do nothing on pages with "Continued" on and if a page does not have "Continued" on and it is even numbered then I need it to move it down i.e. from page number 2 to page number 3 by inserting a blank page on page 2. Thanks for all your help so far Paul and it is encouraging it works for you. Stephen. |
#10
|
||||
|
||||
A screen-shot isn't much good. I would need to see the actual document. That said, it appears you have a page break in the field code in addition to the one the {QUOTE 12} field would create.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Hi Paul,
Please find attached file. Thanks, Stephen. |
#12
|
||||
|
||||
I stripped down your mailmerge main document to the basics and attached it to a data source with just the RunTotal field and an IF test that adds some extra lines in if the RunTotal field contains 'Continued' - so as to force the condition that would generate a second page. I then completed the merge and found the results to be expected. See attached.
Note: If you open the Output document and toggle Word's field code display 'on', that will cause the document to display a field like: {={=MOD({PAGE},2) \# 0}+1 \# ";;'......Page Break...... Blank page'"} with 'Blank page' on the second page, but that's only because you have Word's field code display toggled 'on'.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Hi Paul,
Very sorry I know it will be me but I still can't get it to work, it doesn't seem to do anything. I have attached 2 files one with my code in and the other is a mailmerge example (it only contains demonstration data so there is nothing confidential in there). For the mailmerge what I need to happen is: Page 1 - take no action Page 2 - because page 2 does not display "Continued" and it is an even page number it needs to insert a blank page here otherwise we would print off and send a statement to the first customer with the other customers information on the back page as they print duplex. Page 3 - needs to display Abingtons details as this has been moved down from page 2. Amazon customer - these 3 pages will be printed together and again with the same logic where it will start printing on an odd page and as there are 3 pages it will insert a blank page on 4th page so the next customer starts on a separate sheet of paper. So it is only if there is a total on an even page number and the page above does not display "Continued" then it needs to insert a blank page. Hope this makes sense and thanks for your patience. Stephen. |
#14
|
||||
|
||||
No attachments.
Do note that, in a letter mailmerge, each record is separated by a Section break, which results in the page numbering being reset to 1 for each record - the page #s don't increment in the same way they would in an ordinary document. If each record is only ever a single page, you could replace the {PAGE} field in the field code with a {SECTION} field. Alternatively, you should be able to configure the printer to insert a sheet feed between Sections (you may need to combine this with configuring the mailmerge main document to use a 'different first page' layout).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
Hi Paul,
Thank you. The best we have achieved is a new page for each customer except if "Continued" is on the page. Are you saying it cannot use the page numbers as they are reset for each record and each record may be 1 page or multiple pages? Thanks, Stephen. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Microsoft Word IF statement issues | micro44 | Word | 4 | 10-23-2014 12:10 PM |
Help with IF statement in word 2010 | Mad | Word | 2 | 04-06-2013 06:31 AM |
Mailmerge to Email with a mailmerge attachment | Baldeagle | Mail Merge | 8 | 02-11-2013 04:40 AM |
Mailmerge to Email with a mailmerge attachment | Baldeagle | Mail Merge | 13 | 05-29-2012 02:04 PM |
Word Mailmerge wont print | aovc | Mail Merge | 1 | 05-06-2011 05:29 AM |