Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-11-2011, 08:21 AM
Caroline Caroline is offline Making the IF field work (not Mail Merge) Windows XP Making the IF field work (not Mail Merge) Office 2007
Novice
Making the IF field work (not Mail Merge)
 
Join Date: Feb 2011
Posts: 17
Caroline is on a distinguished road
Default Making the IF field work (not Mail Merge)

My templates have custom properties for things like course number, course title, etc., and fields in the headers and footers that reference the docproperties.



This is the way we did it when I was working in Word 2003. I had to hit the ground running when I moved to a 2007 environment and I haven't had time to learn about QuickParts, which I assume would get me the same result.

But everything is working as intended -- my users are ecstatic that they don't have to fight with typing inside the headers and footers any more (and so far they're complying with my dire warnings about messing with the section breaks, so the headers and footers actually work correctly!) So for the moment I'm sticking with this strategy.

But I'm running into a problem with "conditional text" using the IF field. I want to insert the string "(Instructor)" in the footer IF the _Instructor docproperty is set to Yes (it's a Yes/No field), and insert nothing if it's set to No.

According to the only documentation I can find (Examples of IF fields for Word 2003), it looks to me like this should work:
{ IF {DOCPROPERTY _Instructor} = Yes "(Instructor)" " " \* MERGEFORMAT }
But it returns this:
_Instructor}
which is obviously not what I want.

Putting "Yes" in quotes doesn't help; putting the field name in quotes doesn't help (although my simple DocProperty fields in the header and footer DO have the field name in quotes).

I feel like this should be a simple thing to do...I can't understand what I'm missing.

Any thoughts? Thanks in advance!

Caroline
Reply With Quote
  #2  
Old 04-11-2011, 08:28 AM
Caroline Caroline is offline Making the IF field work (not Mail Merge) Windows XP Making the IF field work (not Mail Merge) Office 2007
Novice
Making the IF field work (not Mail Merge)
 
Join Date: Feb 2011
Posts: 17
Caroline is on a distinguished road
Default Curioser and curioser

I realized that the example actually had spaces inside the nested brackets
{ DOCPROPERTY = _Instructor }
instead of
{DOCPROPERTY = _Instructor}.
When I make this change and update the field, I get
DOCPROPERTY
instead of
_Instructor}
Not sure if this is progress or not...
Reply With Quote
  #3  
Old 04-11-2011, 09:01 AM
Caroline Caroline is offline Making the IF field work (not Mail Merge) Windows XP Making the IF field work (not Mail Merge) Office 2007
Novice
Making the IF field work (not Mail Merge)
 
Join Date: Feb 2011
Posts: 17
Caroline is on a distinguished road
Default Fixed!

Wow.

1. When a Yes or No property is set to "Yes," the expression to compare it to is "Y," not "Yes." I hadn't gotten around to researching that particular question yet...

2. The nested brackets ( "{ DOCPROPERTY "_Instructor" } aren't just any curly braces -- they have to be Word's magic field brackets created using Insert -> Field.

So. In case this will be of use to anyone else, here's the way to display conditional text using document properties and field codes:
{ IF { DOCPROPERTY "_Instructor" } = "Y" "(Instructor)" " " \* MERGEFORMAT }
where all the brackets are magic and all the spaces are essential. (I feel like Garrison Keilor...)

Thanks for a forum where I could puzzle this out myself!

Caroline
Reply With Quote
  #4  
Old 04-11-2011, 02:21 PM
macropod's Avatar
macropod macropod is offline Making the IF field work (not Mail Merge) Windows 7 32bit Making the IF field work (not Mail Merge) Office 2000
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

Hi Caroline,

Glad to see you got it sorted. Whenever you see text representations of field codes, with the '{ }' or '« »', that almost invariably means you need to insert a real field at that point. The chevrons (ie '« »') represent mergefields as they appear when inserted from the mailmerge toolbar

There is another way, other than using Insert|Field for creating fields, and that's to press Ctrl-F9. For your particular example, you could simply press Ctrl-F9 twice to create a pair of nested fields (ie '{ { } }'), then fill in/around the field braces with the required expressions. And, if you find a complex field that you want to re-create, head over to:
http://www.gmayor.com/export_field.htm#TextToField
for a macro I developed to convert the text representation to a working field.

FWIW, you don't need the \* MERGEFORMAT switch, either.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 04-11-2011, 02:50 PM
Caroline Caroline is offline Making the IF field work (not Mail Merge) Windows XP Making the IF field work (not Mail Merge) Office 2007
Novice
Making the IF field work (not Mail Merge)
 
Join Date: Feb 2011
Posts: 17
Caroline is on a distinguished road
Default Ctrl + F9

Paul, thank you!

I used to use Ctrl + F9 constantly as an indexer, but I had completely forgotten it (I didn't know I was that good at compartmentalizing!) Of course!

& thanks for the tip about the MERGEFORMAT switch.

So just for future reference, would QuickParts give me an easier way to automate the header and footer content than having my users go into the Properties dialog (which is not quite as easy to get to in 2007), and then manually updating the headers and footers?

Luckily I've got some pretty savvy users at the moment, but these templates will eventually go out to contractors, and I can't guarantee they'll all read the instructions. The more foolproof I can make this, the better!

Thanks again,
Caroline
Reply With Quote
  #6  
Old 04-11-2011, 04:17 PM
macropod's Avatar
macropod macropod is offline Making the IF field work (not Mail Merge) Windows 7 32bit Making the IF field work (not Mail Merge) Office 2000
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 Caroline View Post
So just for future reference, would QuickParts give me an easier way to automate the header and footer content than having my users go into the Properties dialog (which is not quite as easy to get to in 2007), and then manually updating the headers and footers?
Only if the QuickParts list the properties you're interested in - your custom Instructor property, for example, won't appear.

However, there may be another way of meeting your needs. If you have, say, a title page where all the details you want to have appear in the Header/Footer can go in one or more paragraphs with their own unique Styles applied, then you could use StyleRef fields in the Header/Footer to replicate those details. For example, you might create a 'character' Style named 'Instructor' spanning a MACROBUTTON field coded as:
{MACROBUTTON NoMacro Type the Instructor Name here}
and a STYLEREF field in the header coded as:
{STYLEREF Instructor}

The MACROBUTTON field will appear in the document as 'Type the Instructor Name here' and, as soon as the user starts typing there, will be deleted and replaced by whatever they type. Simultaneously, the header contents will update with the same data.

You could have multiple such MACROBUTTON fields with their own Styles and corresponding STYLEREF field in the header or footer. There are other ways of doing the same kind of thing without MACROBUTTON fields (eg a table with various cells formatted in the relevant Styles), but I thought you might be interested in this way.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making the IF field work (not Mail Merge) confusion with merge and field codes BluRay Mail Merge 5 03-29-2011 01:06 AM
Making the IF field work (not Mail Merge) Merge field in header disappearing Medievalguy88 Word 2 01-06-2011 08:19 AM
Making the IF field work (not Mail Merge) Selecting merge field based on whether or not text is present amym Mail Merge 1 12-07-2010 05:14 AM
Mail merge Field Code Manipulation macjnr Mail Merge 0 09-10-2009 11:37 AM
Making the IF field work (not Mail Merge) mail merge making me crazy oreomax Mail Merge 3 06-16-2009 06:53 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:13 PM.


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