Supress blank lines in DOCPROPERTY field

M

Mary

I use Word 2000 in Windows XP. I'm working on a document where a number of
text items are pulled from Document Properties using the DOCPROPERTY field.
Is there a way to supress the fields if blank? For example, in a cover
letter, the codes for the addressee fields are as follows:
[ DOCPROPERTY "CCname" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd1" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd2" \* MERGEFORMAT ]
[ DOCPROPERTY "CCtownpostcode" \* MERGEFORMAT ]

Each of these field codes is followed by a regular paragraph marker. If
Address 2 is blank in Doc Properties, I still get a blank line. Is there a
way to suppress the third line, referring to add2, if there is no matching
entry? I think the solution probably lies in combining two instructions
within a single field code and putting a paragraph return in the middle of
it. I suspect the IF function is also involved but just can figure it out.
There does not seem to be a way to do this using the Insert Field command,
so presumably it has to be set up manually?
 
J

Jay Freedman

Hi, Mary,

All your assumptions are correct -- you have to use an IF field with a
paragraph mark embedded in it, and you do have to construct it manually
without the dialog. It looks pretty nasty, but it does work.

In the following field code, each pair of curly braces is created by
pressing Ctrl+F9. The ¶ symbol indicates pressing the Enter key (you can see
this if you click the Show All button on the toolbar), and the quote mark
following it will appear on the next line. The correct placement of braces
and quotes is critical.

{IF {DOCPROPERTY "CCadd2"} <> "Error! Unknown document property name."
"{DOCPROPERTY "CCadd2" \* MERGEFORMAT}¶" ""}
 
M

Mary

Jay,

Thank you for your quick answer. Does the following string:
<>"Error! Unknown document property name."
belong in the fieldcode? I tried it just as you presented and still get a
paragraph preceded by a paragraph symbol with field code shading. Does the
<> in what you suggested just mean those two characters on the keyboard?


Jay Freedman said:
Hi, Mary,

All your assumptions are correct -- you have to use an IF field with a
paragraph mark embedded in it, and you do have to construct it manually
without the dialog. It looks pretty nasty, but it does work.

In the following field code, each pair of curly braces is created by
pressing Ctrl+F9. The ¶ symbol indicates pressing the Enter key (you can see
this if you click the Show All button on the toolbar), and the quote mark
following it will appear on the next line. The correct placement of braces
and quotes is critical.

{IF {DOCPROPERTY "CCadd2"} <> "Error! Unknown document property name."
"{DOCPROPERTY "CCadd2" \* MERGEFORMAT}¶" ""}

--
Regards,
Jay Freedman
Microsoft Word MVP
I use Word 2000 in Windows XP. I'm working on a document where a
number of text items are pulled from Document Properties using the
DOCPROPERTY field. Is there a way to supress the fields if blank? For
example, in a cover letter, the codes for the addressee fields are as
follows: [ DOCPROPERTY "CCname" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd1" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd2" \* MERGEFORMAT ]
[ DOCPROPERTY "CCtownpostcode" \* MERGEFORMAT ]

Each of these field codes is followed by a regular paragraph marker.
If Address 2 is blank in Doc Properties, I still get a blank line.
Is there a way to suppress the third line, referring to add2, if
there is no matching entry? I think the solution probably lies in
combining two instructions within a single field code and putting a
paragraph return in the middle of it. I suspect the IF function is
also involved but just can figure it out. There does not seem to be a
way to do this using the Insert Field command, so presumably it has
to be set up manually?
 
J

Jay Freedman

Hi, Mary,

The answer to both your questions is "yes".

The easiest way to tackle the job is just to copy the whole field code
from my message, paste it into the Word document, and then take the
following steps to clean it up:

- Delete the >> marks at the beginning of each line, which were
inserted by the newsreader, and delete the line break so it all
becomes one line.

- Select the first occurrence of the string DOCPROPERTY "CCadd2" and
press Ctrl+F9. Delete the typed braces that are now redundant.

- Select the string DOCPROPERTY "CCadd2" \* MERGEFORMAT and press
Ctrl+F9. Delete the typed braces.

- Select everything from IF to the last quote mark and press Ctrl+F9.
Delete the typed braces.

- Delete the ¶ symbol and press the Enter key there.

- Update the field. The code should disappear and be replaced by
either the content of the CCadd2 property if it exists, followed by
the paragraph break that's inside the field, or else nothing if the
property is not defined.

Mary said:
Jay,

Thank you for your quick answer. Does the following string:
<>"Error! Unknown document property name."
belong in the fieldcode? I tried it just as you presented and still get a
paragraph preceded by a paragraph symbol with field code shading. Does the
<> in what you suggested just mean those two characters on the keyboard?


Jay Freedman said:
Hi, Mary,

All your assumptions are correct -- you have to use an IF field with a
paragraph mark embedded in it, and you do have to construct it manually
without the dialog. It looks pretty nasty, but it does work.

In the following field code, each pair of curly braces is created by
pressing Ctrl+F9. The ¶ symbol indicates pressing the Enter key (you can see
this if you click the Show All button on the toolbar), and the quote mark
following it will appear on the next line. The correct placement of braces
and quotes is critical.

{IF {DOCPROPERTY "CCadd2"} <> "Error! Unknown document property name."
"{DOCPROPERTY "CCadd2" \* MERGEFORMAT}¶" ""}

--
Regards,
Jay Freedman
Microsoft Word MVP
I use Word 2000 in Windows XP. I'm working on a document where a
number of text items are pulled from Document Properties using the
DOCPROPERTY field. Is there a way to supress the fields if blank? For
example, in a cover letter, the codes for the addressee fields are as
follows: [ DOCPROPERTY "CCname" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd1" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd2" \* MERGEFORMAT ]
[ DOCPROPERTY "CCtownpostcode" \* MERGEFORMAT ]

Each of these field codes is followed by a regular paragraph marker.
If Address 2 is blank in Doc Properties, I still get a blank line.
Is there a way to suppress the third line, referring to add2, if
there is no matching entry? I think the solution probably lies in
combining two instructions within a single field code and putting a
paragraph return in the middle of it. I suspect the IF function is
also involved but just can figure it out. There does not seem to be a
way to do this using the Insert Field command, so presumably it has
to be set up manually?
 
M

Mary

Hi Jay:



One thing I was doing wrong was that pasting in the paragraph mark directly
from your message instead of hitting the enter key. I've followed your
instructions exactly but still ended up with an empty paragraph when the
CCadd2 property doesn't exist. I had an "aha" moment and thought if I just
removed the paragraph marker between this field and the CCtownpostcode
following it, that I would no longer get an empty paragraph but I still get
a blank line. I had an "aha2" and removed the paragraph mark at the end of
the previous field (CCadd1) and that works if the CCadd2 is blank but if
not, I end up with the CCadd1 and CCadd2 result on the same line.



I'm trying to understand what the field code is saying. Is it something like
this?

if CCadd2 is false (i.e. returns the message "Error! Unknown document
property") then insert nothing (nothing indicated by <>) but if CCadd2 is
true (it exists) then insert the property and start a new paragraph.

What is the function of the pair of quotation marks at the end of the field,
after ¶"







Jay Freedman said:
Hi, Mary,

The answer to both your questions is "yes".

The easiest way to tackle the job is just to copy the whole field code
from my message, paste it into the Word document, and then take the
following steps to clean it up:

- Delete the >> marks at the beginning of each line, which were
inserted by the newsreader, and delete the line break so it all
becomes one line.

- Select the first occurrence of the string DOCPROPERTY "CCadd2" and
press Ctrl+F9. Delete the typed braces that are now redundant.

- Select the string DOCPROPERTY "CCadd2" \* MERGEFORMAT and press
Ctrl+F9. Delete the typed braces.

- Select everything from IF to the last quote mark and press Ctrl+F9.
Delete the typed braces.

- Delete the ¶ symbol and press the Enter key there.

- Update the field. The code should disappear and be replaced by
either the content of the CCadd2 property if it exists, followed by
the paragraph break that's inside the field, or else nothing if the
property is not defined.

Mary said:
Jay,

Thank you for your quick answer. Does the following string:
<>"Error! Unknown document property name."
belong in the fieldcode? I tried it just as you presented and still get a
paragraph preceded by a paragraph symbol with field code shading. Does the
<> in what you suggested just mean those two characters on the keyboard?


Jay Freedman said:
Hi, Mary,

All your assumptions are correct -- you have to use an IF field with a
paragraph mark embedded in it, and you do have to construct it manually
without the dialog. It looks pretty nasty, but it does work.

In the following field code, each pair of curly braces is created by
pressing Ctrl+F9. The ¶ symbol indicates pressing the Enter key (you
can
see
this if you click the Show All button on the toolbar), and the quote mark
following it will appear on the next line. The correct placement of braces
and quotes is critical.

{IF {DOCPROPERTY "CCadd2"} <> "Error! Unknown document property name."
"{DOCPROPERTY "CCadd2" \* MERGEFORMAT}¶" ""}

--
Regards,
Jay Freedman
Microsoft Word MVP

Mary wrote:
I use Word 2000 in Windows XP. I'm working on a document where a
number of text items are pulled from Document Properties using the
DOCPROPERTY field. Is there a way to supress the fields if blank? For
example, in a cover letter, the codes for the addressee fields are as
follows: [ DOCPROPERTY "CCname" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd1" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd2" \* MERGEFORMAT ]
[ DOCPROPERTY "CCtownpostcode" \* MERGEFORMAT ]

Each of these field codes is followed by a regular paragraph marker.
If Address 2 is blank in Doc Properties, I still get a blank line.
Is there a way to suppress the third line, referring to add2, if
there is no matching entry? I think the solution probably lies in
combining two instructions within a single field code and putting a
paragraph return in the middle of it. I suspect the IF function is
also involved but just can figure it out. There does not seem to be a
way to do this using the Insert Field command, so presumably it has
to be set up manually?
 
J

Jay Freedman

Hi Mary

The <> symbol means "not equal". The field says

IF the result of the DOCPROPERTY field is not equal to the "Error!"
message, then insert the result of the DOCPROPERTY field followed by a
paragraph mark.

If the result *is* the "Error!" message -- which occurs when CCadd2
doesn't exist, but *not* when it contains a blank -- then insert
nothing (signified by the empty pair of quotes you mentioned). The
empty quotes aren't really necessary, and the field operates the same
without them.

Deleting the paragraph mark between this IF field and the
CCtownpostcode following it is the correct thing to do. After that
deletion, if there's still a blank line when CCaddr2 doesn't exist,
that means the paragraph mark inside the field isn't in the right
place.

Since this is proving almost impossible to describe properly in a
newsgroup post, I've placed a sample file for you at
http://members.verizon.net/~vze27sds/downloads/docprop.doc.

Mary said:
Hi Jay:

One thing I was doing wrong was that pasting in the paragraph mark directly
from your message instead of hitting the enter key. I've followed your
instructions exactly but still ended up with an empty paragraph when the
CCadd2 property doesn't exist. I had an "aha" moment and thought if I just
removed the paragraph marker between this field and the CCtownpostcode
following it, that I would no longer get an empty paragraph but I still get
a blank line. I had an "aha2" and removed the paragraph mark at the end of
the previous field (CCadd1) and that works if the CCadd2 is blank but if
not, I end up with the CCadd1 and CCadd2 result on the same line.



I'm trying to understand what the field code is saying. Is it something like
this?

if CCadd2 is false (i.e. returns the message "Error! Unknown document
property") then insert nothing (nothing indicated by <>) but if CCadd2 is
true (it exists) then insert the property and start a new paragraph.

What is the function of the pair of quotation marks at the end of the field,
after ¶"


Jay Freedman said:
Hi, Mary,

The answer to both your questions is "yes".

The easiest way to tackle the job is just to copy the whole field code
from my message, paste it into the Word document, and then take the
following steps to clean it up:

- Delete the >> marks at the beginning of each line, which were
inserted by the newsreader, and delete the line break so it all
becomes one line.

- Select the first occurrence of the string DOCPROPERTY "CCadd2" and
press Ctrl+F9. Delete the typed braces that are now redundant.

- Select the string DOCPROPERTY "CCadd2" \* MERGEFORMAT and press
Ctrl+F9. Delete the typed braces.

- Select everything from IF to the last quote mark and press Ctrl+F9.
Delete the typed braces.

- Delete the ¶ symbol and press the Enter key there.

- Update the field. The code should disappear and be replaced by
either the content of the CCadd2 property if it exists, followed by
the paragraph break that's inside the field, or else nothing if the
property is not defined.

Mary said:
Jay,

Thank you for your quick answer. Does the following string:
<>"Error! Unknown document property name."
belong in the fieldcode? I tried it just as you presented and still get a
paragraph preceded by a paragraph symbol with field code shading. Does the
<> in what you suggested just mean those two characters on the keyboard?


Hi, Mary,

All your assumptions are correct -- you have to use an IF field with a
paragraph mark embedded in it, and you do have to construct it manually
without the dialog. It looks pretty nasty, but it does work.

In the following field code, each pair of curly braces is created by
pressing Ctrl+F9. The ¶ symbol indicates pressing the Enter key (you can
see
this if you click the Show All button on the toolbar), and the quote mark
following it will appear on the next line. The correct placement of braces
and quotes is critical.

{IF {DOCPROPERTY "CCadd2"} <> "Error! Unknown document property name."
"{DOCPROPERTY "CCadd2" \* MERGEFORMAT}¶" ""}

--
Regards,
Jay Freedman
Microsoft Word MVP

Mary wrote:
I use Word 2000 in Windows XP. I'm working on a document where a
number of text items are pulled from Document Properties using the
DOCPROPERTY field. Is there a way to supress the fields if blank? For
example, in a cover letter, the codes for the addressee fields are as
follows: [ DOCPROPERTY "CCname" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd1" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd2" \* MERGEFORMAT ]
[ DOCPROPERTY "CCtownpostcode" \* MERGEFORMAT ]

Each of these field codes is followed by a regular paragraph marker.
If Address 2 is blank in Doc Properties, I still get a blank line.
Is there a way to suppress the third line, referring to add2, if
there is no matching entry? I think the solution probably lies in
combining two instructions within a single field code and putting a
paragraph return in the middle of it. I suspect the IF function is
also involved but just can figure it out. There does not seem to be a
way to do this using the Insert Field command, so presumably it has
to be set up manually?
 
M

Mary

Hi Jay,

Thank you for going to so much trouble. I did have the field codes exactly
as you show them in your example. In your doc, I can't completely delete the
value in the CCadd2 property -- I can replace it with a single space but
this still allow a paragraph mark to print. The only way I can get it to
behave is to delete the property name itself. While that has the desired
effect in the document you provided, I'm not sure it will work in mine. I'm
not the owner of the file. It's a proposal template and on first creating a
new file based on the template, it's set up so that the user is first
presented with a Document Properties window. Fill-ins on this screen are
used to populate fields in the document itself. But if CCadd2 (or any other
value) is not filled in, it will result in an empty paragraph and the
property itself cannot be deleted on this window. Deleting it by going into
File-->Properties-->Custom, results in an error message.

So I'm guessing it's best to just live with the paragraph marks and delete
them manually.


Jay Freedman said:
Hi Mary

The <> symbol means "not equal". The field says

IF the result of the DOCPROPERTY field is not equal to the "Error!"
message, then insert the result of the DOCPROPERTY field followed by a
paragraph mark.

If the result *is* the "Error!" message -- which occurs when CCadd2
doesn't exist, but *not* when it contains a blank -- then insert
nothing (signified by the empty pair of quotes you mentioned). The
empty quotes aren't really necessary, and the field operates the same
without them.

Deleting the paragraph mark between this IF field and the
CCtownpostcode following it is the correct thing to do. After that
deletion, if there's still a blank line when CCaddr2 doesn't exist,
that means the paragraph mark inside the field isn't in the right
place.

Since this is proving almost impossible to describe properly in a
newsgroup post, I've placed a sample file for you at
http://members.verizon.net/~vze27sds/downloads/docprop.doc.

Mary said:
Hi Jay:

One thing I was doing wrong was that pasting in the paragraph mark directly
from your message instead of hitting the enter key. I've followed your
instructions exactly but still ended up with an empty paragraph when the
CCadd2 property doesn't exist. I had an "aha" moment and thought if I just
removed the paragraph marker between this field and the CCtownpostcode
following it, that I would no longer get an empty paragraph but I still get
a blank line. I had an "aha2" and removed the paragraph mark at the end of
the previous field (CCadd1) and that works if the CCadd2 is blank but if
not, I end up with the CCadd1 and CCadd2 result on the same line.



I'm trying to understand what the field code is saying. Is it something like
this?

if CCadd2 is false (i.e. returns the message "Error! Unknown document
property") then insert nothing (nothing indicated by <>) but if CCadd2 is
true (it exists) then insert the property and start a new paragraph.

What is the function of the pair of quotation marks at the end of the field,
after ¶"


Jay Freedman said:
Hi, Mary,

The answer to both your questions is "yes".

The easiest way to tackle the job is just to copy the whole field code
from my message, paste it into the Word document, and then take the
following steps to clean it up:

- Delete the >> marks at the beginning of each line, which were
inserted by the newsreader, and delete the line break so it all
becomes one line.

- Select the first occurrence of the string DOCPROPERTY "CCadd2" and
press Ctrl+F9. Delete the typed braces that are now redundant.

- Select the string DOCPROPERTY "CCadd2" \* MERGEFORMAT and press
Ctrl+F9. Delete the typed braces.

- Select everything from IF to the last quote mark and press Ctrl+F9.
Delete the typed braces.

- Delete the ¶ symbol and press the Enter key there.

- Update the field. The code should disappear and be replaced by
either the content of the CCadd2 property if it exists, followed by
the paragraph break that's inside the field, or else nothing if the
property is not defined.


Jay,

Thank you for your quick answer. Does the following string:
<>"Error! Unknown document property name."
belong in the fieldcode? I tried it just as you presented and still get a
paragraph preceded by a paragraph symbol with field code shading. Does the
<> in what you suggested just mean those two characters on the keyboard?


Hi, Mary,

All your assumptions are correct -- you have to use an IF field with a
paragraph mark embedded in it, and you do have to construct it manually
without the dialog. It looks pretty nasty, but it does work.

In the following field code, each pair of curly braces is created by
pressing Ctrl+F9. The ¶ symbol indicates pressing the Enter key (you can
see
this if you click the Show All button on the toolbar), and the quote mark
following it will appear on the next line. The correct placement of braces
and quotes is critical.

{IF {DOCPROPERTY "CCadd2"} <> "Error! Unknown document property name."
"{DOCPROPERTY "CCadd2" \* MERGEFORMAT}¶" ""}

--
Regards,
Jay Freedman
Microsoft Word MVP

Mary wrote:
I use Word 2000 in Windows XP. I'm working on a document where a
number of text items are pulled from Document Properties using the
DOCPROPERTY field. Is there a way to supress the fields if blank? For
example, in a cover letter, the codes for the addressee fields are as
follows: [ DOCPROPERTY "CCname" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd1" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd2" \* MERGEFORMAT ]
[ DOCPROPERTY "CCtownpostcode" \* MERGEFORMAT ]

Each of these field codes is followed by a regular paragraph marker.
If Address 2 is blank in Doc Properties, I still get a blank line.
Is there a way to suppress the third line, referring to add2, if
there is no matching entry? I think the solution probably lies in
combining two instructions within a single field code and putting a
paragraph return in the middle of it. I suspect the IF function is
also involved but just can figure it out. There does not seem to be a
way to do this using the Insert Field command, so presumably it has
to be set up manually?
 
J

Jay Freedman

Hi Mary

One more try... I had a suspicion you were putting in a blank instead
of deleting the property, but your description used different terms in
different places and I wasn't sure.

In the field code I gave you, take out the error message (Error!
Unknown document property name.) and put in a single space between the
quotes. In other words, you're changing the IF condition from 'if the
field result is not the error message' to 'if the field result is not
a single space character'. The rest of the field code remains the
same.

Note that if you type two or more spaces in the property dialog, the
"blank" line (spaces and a paragraph mark) will appear. If it's just
one space, both the space and the paragraph mark will disappear.

Mary said:
Hi Jay,

Thank you for going to so much trouble. I did have the field codes exactly
as you show them in your example. In your doc, I can't completely delete the
value in the CCadd2 property -- I can replace it with a single space but
this still allow a paragraph mark to print. The only way I can get it to
behave is to delete the property name itself. While that has the desired
effect in the document you provided, I'm not sure it will work in mine. I'm
not the owner of the file. It's a proposal template and on first creating a
new file based on the template, it's set up so that the user is first
presented with a Document Properties window. Fill-ins on this screen are
used to populate fields in the document itself. But if CCadd2 (or any other
value) is not filled in, it will result in an empty paragraph and the
property itself cannot be deleted on this window. Deleting it by going into
File-->Properties-->Custom, results in an error message.

So I'm guessing it's best to just live with the paragraph marks and delete
them manually.


Jay Freedman said:
Hi Mary

The <> symbol means "not equal". The field says

IF the result of the DOCPROPERTY field is not equal to the "Error!"
message, then insert the result of the DOCPROPERTY field followed by a
paragraph mark.

If the result *is* the "Error!" message -- which occurs when CCadd2
doesn't exist, but *not* when it contains a blank -- then insert
nothing (signified by the empty pair of quotes you mentioned). The
empty quotes aren't really necessary, and the field operates the same
without them.

Deleting the paragraph mark between this IF field and the
CCtownpostcode following it is the correct thing to do. After that
deletion, if there's still a blank line when CCaddr2 doesn't exist,
that means the paragraph mark inside the field isn't in the right
place.

Since this is proving almost impossible to describe properly in a
newsgroup post, I've placed a sample file for you at
http://members.verizon.net/~vze27sds/downloads/docprop.doc.

Mary said:
Hi Jay:

One thing I was doing wrong was that pasting in the paragraph mark directly
from your message instead of hitting the enter key. I've followed your
instructions exactly but still ended up with an empty paragraph when the
CCadd2 property doesn't exist. I had an "aha" moment and thought if I just
removed the paragraph marker between this field and the CCtownpostcode
following it, that I would no longer get an empty paragraph but I still get
a blank line. I had an "aha2" and removed the paragraph mark at the end of
the previous field (CCadd1) and that works if the CCadd2 is blank but if
not, I end up with the CCadd1 and CCadd2 result on the same line.



I'm trying to understand what the field code is saying. Is it something like
this?

if CCadd2 is false (i.e. returns the message "Error! Unknown document
property") then insert nothing (nothing indicated by <>) but if CCadd2 is
true (it exists) then insert the property and start a new paragraph.

What is the function of the pair of quotation marks at the end of the field,
after ¶"


Hi, Mary,

The answer to both your questions is "yes".

The easiest way to tackle the job is just to copy the whole field code
from my message, paste it into the Word document, and then take the
following steps to clean it up:

- Delete the >> marks at the beginning of each line, which were
inserted by the newsreader, and delete the line break so it all
becomes one line.

- Select the first occurrence of the string DOCPROPERTY "CCadd2" and
press Ctrl+F9. Delete the typed braces that are now redundant.

- Select the string DOCPROPERTY "CCadd2" \* MERGEFORMAT and press
Ctrl+F9. Delete the typed braces.

- Select everything from IF to the last quote mark and press Ctrl+F9.
Delete the typed braces.

- Delete the ¶ symbol and press the Enter key there.

- Update the field. The code should disappear and be replaced by
either the content of the CCadd2 property if it exists, followed by
the paragraph break that's inside the field, or else nothing if the
property is not defined.


Jay,

Thank you for your quick answer. Does the following string:
<>"Error! Unknown document property name."
belong in the fieldcode? I tried it just as you presented and still get a
paragraph preceded by a paragraph symbol with field code shading. Does
the
<> in what you suggested just mean those two characters on the keyboard?


Hi, Mary,

All your assumptions are correct -- you have to use an IF field with a
paragraph mark embedded in it, and you do have to construct it manually
without the dialog. It looks pretty nasty, but it does work.

In the following field code, each pair of curly braces is created by
pressing Ctrl+F9. The ¶ symbol indicates pressing the Enter key (you
can
see
this if you click the Show All button on the toolbar), and the quote
mark
following it will appear on the next line. The correct placement of
braces
and quotes is critical.

{IF {DOCPROPERTY "CCadd2"} <> "Error! Unknown document property name."
"{DOCPROPERTY "CCadd2" \* MERGEFORMAT}¶" ""}

--
Regards,
Jay Freedman
Microsoft Word MVP

Mary wrote:
I use Word 2000 in Windows XP. I'm working on a document where a
number of text items are pulled from Document Properties using the
DOCPROPERTY field. Is there a way to supress the fields if blank? For
example, in a cover letter, the codes for the addressee fields are as
follows: [ DOCPROPERTY "CCname" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd1" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd2" \* MERGEFORMAT ]
[ DOCPROPERTY "CCtownpostcode" \* MERGEFORMAT ]

Each of these field codes is followed by a regular paragraph marker.
If Address 2 is blank in Doc Properties, I still get a blank line.
Is there a way to suppress the third line, referring to add2, if
there is no matching entry? I think the solution probably lies in
combining two instructions within a single field code and putting a
paragraph return in the middle of it. I suspect the IF function is
also involved but just can figure it out. There does not seem to be a
way to do this using the Insert Field command, so presumably it has
to be set up manually?
 
M

Mary

Jay, that did it! Thanks for being so persistent.
Is there somewhere I can learn more about creating and editing field
codes? -- I'm sure all the answers are somewhere within Word's Help but I
never know the right questions to ask it.


Jay Freedman said:
Hi Mary

One more try... I had a suspicion you were putting in a blank instead
of deleting the property, but your description used different terms in
different places and I wasn't sure.

In the field code I gave you, take out the error message (Error!
Unknown document property name.) and put in a single space between the
quotes. In other words, you're changing the IF condition from 'if the
field result is not the error message' to 'if the field result is not
a single space character'. The rest of the field code remains the
same.

Note that if you type two or more spaces in the property dialog, the
"blank" line (spaces and a paragraph mark) will appear. If it's just
one space, both the space and the paragraph mark will disappear.

Mary said:
Hi Jay,

Thank you for going to so much trouble. I did have the field codes exactly
as you show them in your example. In your doc, I can't completely delete the
value in the CCadd2 property -- I can replace it with a single space but
this still allow a paragraph mark to print. The only way I can get it to
behave is to delete the property name itself. While that has the desired
effect in the document you provided, I'm not sure it will work in mine. I'm
not the owner of the file. It's a proposal template and on first creating a
new file based on the template, it's set up so that the user is first
presented with a Document Properties window. Fill-ins on this screen are
used to populate fields in the document itself. But if CCadd2 (or any other
value) is not filled in, it will result in an empty paragraph and the
property itself cannot be deleted on this window. Deleting it by going into
File-->Properties-->Custom, results in an error message.

So I'm guessing it's best to just live with the paragraph marks and delete
them manually.


Jay Freedman said:
Hi Mary

The <> symbol means "not equal". The field says

IF the result of the DOCPROPERTY field is not equal to the "Error!"
message, then insert the result of the DOCPROPERTY field followed by a
paragraph mark.

If the result *is* the "Error!" message -- which occurs when CCadd2
doesn't exist, but *not* when it contains a blank -- then insert
nothing (signified by the empty pair of quotes you mentioned). The
empty quotes aren't really necessary, and the field operates the same
without them.

Deleting the paragraph mark between this IF field and the
CCtownpostcode following it is the correct thing to do. After that
deletion, if there's still a blank line when CCaddr2 doesn't exist,
that means the paragraph mark inside the field isn't in the right
place.

Since this is proving almost impossible to describe properly in a
newsgroup post, I've placed a sample file for you at
http://members.verizon.net/~vze27sds/downloads/docprop.doc.


Hi Jay:

One thing I was doing wrong was that pasting in the paragraph mark directly
from your message instead of hitting the enter key. I've followed your
instructions exactly but still ended up with an empty paragraph when the
CCadd2 property doesn't exist. I had an "aha" moment and thought if I just
removed the paragraph marker between this field and the CCtownpostcode
following it, that I would no longer get an empty paragraph but I
still
get
a blank line. I had an "aha2" and removed the paragraph mark at the
end
of
the previous field (CCadd1) and that works if the CCadd2 is blank but if
not, I end up with the CCadd1 and CCadd2 result on the same line.



I'm trying to understand what the field code is saying. Is it
something
like
this?

if CCadd2 is false (i.e. returns the message "Error! Unknown document
property") then insert nothing (nothing indicated by <>) but if CCadd2 is
true (it exists) then insert the property and start a new paragraph.

What is the function of the pair of quotation marks at the end of the field,
after ¶"


Hi, Mary,

The answer to both your questions is "yes".

The easiest way to tackle the job is just to copy the whole field code
from my message, paste it into the Word document, and then take the
following steps to clean it up:

- Delete the >> marks at the beginning of each line, which were
inserted by the newsreader, and delete the line break so it all
becomes one line.

- Select the first occurrence of the string DOCPROPERTY "CCadd2" and
press Ctrl+F9. Delete the typed braces that are now redundant.

- Select the string DOCPROPERTY "CCadd2" \* MERGEFORMAT and press
Ctrl+F9. Delete the typed braces.

- Select everything from IF to the last quote mark and press Ctrl+F9.
Delete the typed braces.

- Delete the ¶ symbol and press the Enter key there.

- Update the field. The code should disappear and be replaced by
either the content of the CCadd2 property if it exists, followed by
the paragraph break that's inside the field, or else nothing if the
property is not defined.


Jay,

Thank you for your quick answer. Does the following string:
<>"Error! Unknown document property name."
belong in the fieldcode? I tried it just as you presented and still get a
paragraph preceded by a paragraph symbol with field code shading. Does
the
<> in what you suggested just mean those two characters on the keyboard?


Hi, Mary,

All your assumptions are correct -- you have to use an IF field
with
a
paragraph mark embedded in it, and you do have to construct it manually
without the dialog. It looks pretty nasty, but it does work.

In the following field code, each pair of curly braces is created by
pressing Ctrl+F9. The ¶ symbol indicates pressing the Enter key (you
can
see
this if you click the Show All button on the toolbar), and the quote
mark
following it will appear on the next line. The correct placement of
braces
and quotes is critical.

{IF {DOCPROPERTY "CCadd2"} <> "Error! Unknown document property name."
"{DOCPROPERTY "CCadd2" \* MERGEFORMAT}¶" ""}

--
Regards,
Jay Freedman
Microsoft Word MVP

Mary wrote:
I use Word 2000 in Windows XP. I'm working on a document where a
number of text items are pulled from Document Properties using the
DOCPROPERTY field. Is there a way to supress the fields if
blank?
For
example, in a cover letter, the codes for the addressee fields
are
as
follows: [ DOCPROPERTY "CCname" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd1" \* MERGEFORMAT ]
[ DOCPROPERTY "CCadd2" \* MERGEFORMAT ]
[ DOCPROPERTY "CCtownpostcode" \* MERGEFORMAT ]

Each of these field codes is followed by a regular paragraph marker.
If Address 2 is blank in Doc Properties, I still get a blank line.
Is there a way to suppress the third line, referring to add2, if
there is no matching entry? I think the solution probably lies in
combining two instructions within a single field code and
putting
a
paragraph return in the middle of it. I suspect the IF function is
also involved but just can figure it out. There does not seem
to
be a
way to do this using the Insert Field command, so presumably it has
to be set up manually?
 
J

Jay Freedman

Hi Mary

Glad it finally worked out.

As for the answers being in the Help -- ha! The Help is somewhat bare-bones
on the subject, even when you can figure out the right search terms (and the
search engine has been getting worse through successive releases -- Office
2003 is the worst yet, and the MVPs have made sure MS knows it).

In the Word 2000 Help, read the entries "Field codes: If field" and
"Examples of IF fields". To understand some of the examples, you'll need
"Field codes: = (Formula) field". Within that topic, there are links for
"Operators" and "Functions" that are helpful. You might also get some use
from the topic "Field codes: Compare field".

The word.mvps.org site has some pages that discuss editing field codes,
usually incidental to solving some other problem. For examples, see
http://word.mvps.org/FAQs/Numbering/PageNumbering.htm
http://word.mvps.org/FAQs/MailMerge/MMergeIfFields.htm
http://word.mvps.org/FAQs/TblsFldsFms/AppendixCaptions.htm
http://word.mvps.org/FAQs/TblsFldsFms/InsEvnPgEndChap.htm
http://word.mvps.org/FAQs/TblsFldsFms/UpdateFilename.htm
 
M

Mary

Jay:

Great, I'm going to explore those links in a little while while my fieldcode
taste-buds are still afire.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top