#1
|
|||
|
|||
Need help with Field Codes
I need to create a field which changes based on the location of a bookmark ('CONT' in this example). If the bookmark falls on the next page, it should say 'the following page', otherwise, 'page x'. This is my attempt at doing that here:
If {PageRef CONT} > {Page} + 1 "the following page" "page " {Page} I'm not very familiar with field codes just yet, and, as a programmer, I was expecting some sort of delimiter to separate each section (i.e. the 'true' value from the 'false' value), but that doesn't seem to be how this works. I have tried adding parentheses to group parts together, but that doesn't seem to work either: If ({PageRef CONT} > ({Page} + 1)) "the following page" ("page " {Page}) Can anyone help push me in the correct direction, and give me a working example of what I need to do? Thanks. |
#2
|
|||
|
|||
Ok, I'm making progress constructing the field, I have the following to calculate if the required section is on the next page or not:
=({PAGEREF CONT} > {PAGE} + 1) ...and that is working. Now I need to insert that into an IF statement, and be able to concatenate 'page ' with the page#. I think I may get there eventually. |
#3
|
|||
|
|||
Ok, I finally got it working:
See info on {IF{=({PAGEREF CONT}>{PAGE}+1}>0"page {PAGEREF CONT}" "the following page" } |
#4
|
|||
|
|||
BTW, is there a way to copy the actual fieldcode as text instead of the value?
I had to retype each formula into this forum, and I would like to know if there is a way to make it easier by being able to copy the formula. |
#5
|
||||
|
||||
See http://www.gmayor.com/export_field.htm which shows how to convert fields to text and vice versa.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#6
|
||||
|
||||
Cosmo: I note that you've posted your question in the mailmerge forum. If this is indeed for a mailmerge, you need to be aware that your field code won't work. For starters, it would need to appear more like:
{IF{PAGEREF CONT}>{={PAGE}+1} "page {PAGEREF CONT}" "the following page" } Even then, however, because IF fields get converted to their results immediately the merge for each record is executed, you'd only ever get the "the following page" output. Furthermore, since you can only have one instance of a given bookmark in a document, the bookmarks, too, get deleted. Consequently, all you're left with is field coding that can do something based on the number of pages in a Section. The following construction will do that and survive a mailmerge: {={SECTIONPAGES}-{PAGE}-1 \# "'page {QUOTE{={PAGE}+2}}';;'the following page'"} Note that you'll need to update the fields in the output document (e.g. via Ctrl-A, F9), post-merge, to get the correct text output.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Quote:
|
#8
|
|||
|
|||
Quote:
Quote:
Quote:
I appreciate all of the input. |
#9
|
||||
|
||||
It's converted before it gets a chance to evaluate how many pages the Section will have.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
Quote:
If so, are there other field codes that I need to watch for in merge fields? |
#11
|
||||
|
||||
Most fields get converted, including all MERGEFIELDs, QUOTE fields and IF fields, but formula fields don't. Hence my use of a FORMULA field, but even that contains a QUOTE field to force the {={PAGE}+2} formula to convert to its results...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
Ok, I think I am starting to understand better now. The IF field code(and any embedded field codes within the IF) is converted, but other field codes are not. So if I had a field code which had an embedded IF field code, The IF would be converted, but the parent field code would still be editable?
Wherever I would use an 'IF [condition]', I can convert it to a formula as you have posted for mail merge? Does this work in a normal document that isn't being used for a mail merge? |
#13
|
||||
|
||||
Quote:
Quote:
The field code I provided works because the condition being tested can have its results expressed numerically and, therefore, the numeric picture switches that can be used to format numbers can be coerced into providing the required output. Numeric picture switches cater for +ve, -ve and 0 values to be formatted differently. As you can imagine, things can start getting complicated when there are more than three possible outcomes... The same field construction will work in an ordinary document; the difference being that nothing inside a QUOTE field or IF field gets converted to its results. That's an important limitation because it means tests of volatile values, such as dates, don't become fixed the way they would with a mailmerge. That, in turn, could give invalid results on another day, for example.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#14
|
|||
|
|||
Quote:
Thanks again, your input is greatly appreciated. |
#15
|
|||
|
|||
Ok, I've played around with this, and it doesn't quite work the way I need it to, and if I understand things properly, I don't think I can get it to do what I need.
The problem is that the content that I am referencing is the start of the second section, but it is a continuous section break. So placing the SECTIONPAGES field in the first section, if the section break falls at the beginning of page 4, I get one result (3 pages for the first section) but if it starts in the middle of page 4, I get another result (4 pages for the first section). What I really need to know is what page the NEXT section starts on, not how many pages are in the first section, but I don't see a way to do that other than using a PAGEREF to the bookmarked content, which you indicated doesn't work with a mail merge. Am I missing something, or is this beyond the capabilities within a mail merge? |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Copying Raw Field Codes | ptmuldoon | Word | 3 | 01-04-2015 02:50 PM |
How to hide field codes from others? | lucky16 | Word VBA | 2 | 10-24-2014 03:52 AM |
VBA script to update field codes? | Calab | Word VBA | 1 | 04-07-2014 09:27 PM |
Formula Field using Field Codes | hunter2193 | Word | 3 | 04-05-2013 04:58 AM |
Word Equation field codes | mkarthic | Word | 1 | 12-02-2011 02:09 AM |