Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-23-2015, 12:32 PM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 07-23-2015, 01:32 PM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

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.
Reply With Quote
  #3  
Old 07-23-2015, 01:57 PM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Ok, I finally got it working:

See info on {IF{=({PAGEREF CONT}>{PAGE}+1}>0"page {PAGEREF CONT}" "the following page" }
Reply With Quote
  #4  
Old 07-23-2015, 02:11 PM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 07-23-2015, 08:50 PM
gmayor's Avatar
gmayor gmayor is offline Need help with Field Codes Windows 7 64bit Need help with Field Codes Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #6  
Old 07-24-2015, 12:29 AM
macropod's Avatar
macropod macropod is offline Need help with Field Codes Windows 7 64bit Need help with Field Codes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 07-24-2015, 05:15 AM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
See http://www.gmayor.com/export_field.htm which shows how to convert fields to text and vice versa.
Thanks very much for the link, I will look into this when I get a chance.
Reply With Quote
  #8  
Old 07-24-2015, 05:16 AM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
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" }
Yes this is being used in a mail merge, but it may also be used in a standalone user-entered document.
Quote:
Originally Posted by macropod View Post
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.
Thanks for the info, I was definitely not aware of this. Is the IF field converted before the merge or after? Currently, I have this field at the bottom of the first page, and the CONT bookmark will most likely appear on the second page, but I want to make sure it is flexible enough to handle if the data is longer than an extra page. I may have to put a similar field into the footer for the next section which will need to appear on each page except for the last page, so it sounds like I can't use an IF field for this. Is there a solution that would do this in a mail merge?
Quote:
Originally Posted by macropod View Post
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.
Thanks, I will try this out to see if this does what I need. The bookmark will be the start of the next section

I appreciate all of the input.
Reply With Quote
  #9  
Old 07-24-2015, 05:28 AM
macropod's Avatar
macropod macropod is offline Need help with Field Codes Windows 7 64bit Need help with Field Codes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Cosmo View Post
Is the IF field converted before the merge or after?
It's converted before it gets a chance to evaluate how many pages the Section will have.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 07-24-2015, 05:37 AM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
It's converted before it gets a chance to evaluate how many pages the Section will have.
I'm not sure I quite get how things work here, am I correct in understanding your comments to mean that it's not the field itself that's the problem, but the 'IF' statement in the field that gets converted, where other field codes are not converted?

If so, are there other field codes that I need to watch for in merge fields?
Reply With Quote
  #11  
Old 07-24-2015, 05:45 AM
macropod's Avatar
macropod macropod is offline Need help with Field Codes Windows 7 64bit Need help with Field Codes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #12  
Old 07-24-2015, 06:05 AM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

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?
Reply With Quote
  #13  
Old 07-24-2015, 06:21 AM
macropod's Avatar
macropod macropod is offline Need help with Field Codes Windows 7 64bit Need help with Field Codes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Cosmo View Post
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?
That depends on what else the parent field is contained in. If it's contained in a QUOTE field, for example, the whole lot gets converted.
Quote:
Originally Posted by Cosmo View Post
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?
Whether a formula field can be used in a given situation depends on what you're trying to do. Most of the things you'd want to test can have their results expressed numerically, so that's not a major concern.

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]
Reply With Quote
  #14  
Old 07-24-2015, 07:21 AM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
That depends on what else the parent field is contained in. If it's contained in a QUOTE field, for example, the whole lot gets converted.

Whether a formula field can be used in a given situation depends on what you're trying to do. Most of the things you'd want to test can have their results expressed numerically, so that's not a major concern.

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.
Ok, thanks. Things can get quite complicated and confusing pretty fast. I believe I may have enough information to hopefully get where I need to for this project, after some testing and a little trial and error (or a little trial and a lot of error). I may have a few more questions in the next few days as I get into the details.

Thanks again, your input is greatly appreciated.
Reply With Quote
  #15  
Old 07-28-2015, 07:23 AM
Cosmo Cosmo is offline Need help with Field Codes Windows Vista Need help with Field Codes Office 2007
Competent Performer
Need help with Field Codes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

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?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying Raw Field Codes ptmuldoon Word 3 01-04-2015 02:50 PM
Need help with Field Codes 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
Need help with Field Codes Word Equation field codes mkarthic Word 1 12-02-2011 02:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft