Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenating two DOCPROPERTY fields via field coding 1

Status
Not open for further replies.

soreed

Technical User
Oct 3, 2011
2
GB
thread68-1581008

In this thread - - macropod said "Your best bet is to use two separate DOCPROPERTY fields. It's always possible to concatenate two such fields via field coding, including conditionally inserting a comma & space if both DOCPROPERTY fields have data".

I'd like to do two things -
1. Concatenate two fields and place comma space between them if they're both not empty
2. Do this as a single field (so that it's a single right-click to Update the field)

I think I understand the conditional formatting part (sort of), but don't seem to be able to check for empty properties only specific values.
I could do the second part as three fields (i.e. first property, conditional comma space, second field) but it's cumbersome unless the user does an "update all" which realistically they're not going to do.

What's the smart way to put this all together?

Many thanks in advance!
 

I'm not sure there is a 'smart' way! Fields are complex and macropod is the expert, but I don't think you can combine multiple conditions with string comparands, and what you have to do is check your two DocProperty fields individually, and concatenate with logic like this:

Output FirstProperty
If FirstProperty = "" Then
(output nothing)
Else
If SecondProperty = "" Then
(output nothing)
Else
Output comma separator
EndIf
EndIf
Output SecondProperty

To make it into a single field you could wrap it in a quote. Put it all together as Fields and you get:

{ QUOTE { DOCPROPERTY FirstProperty } { IF "{ DOCPROPERTY FirstProperty }" = "" "" { IF "{ DOCPROPERTY SecondProperty }" = "" "" ", " } } { DOCPROPERTY SecondProperty } }

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Perfect, thank you.

It was the QUOTE command I was missing, plus a syntax error with my IF.

Thanks again!
 
FWIW, the field code could be reduced to:
{QUOTE{DOCPROPERTY FirstProperty}{IF{DOCPROPERTY FirstProperty}<> "" {IF{DOCPROPERTY SecondProperty}<> "" ", "}}{DOCPROPERTY SecondProperty}}

Cheers
Paul Edstein
[MS MVP - Word]
 
Hi Paul,

Technically marginally reduced, I'll grant :) but you can't remove the quotes round the DocProperty fields in the conditions unless you are sure that they don't contain spaces.


Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Hi Tony,

Re:
but you can't remove the quotes round the DocProperty fields in the conditions unless you are sure that they don't contain spaces
Yes you can! It really doesn't matter what the property contains.

Of potentially greater significance to the OP, though, is that a DOCPROPERTY can't be empty - delete the content and the property goes too. In that case, you could simply populate the property with a space and use field coding like:
{QUOTE{DOCPROPERTY FirstProperty}{IF{DOCPROPERTY FirstProperty}<> " " {IF{DOCPROPERTY SecondProperty}<> " " ", "}}{DOCPROPERTY SecondProperty}}
This is essentially the field from my last post with the two "" instances replaced with " ". Alternatively, if you want to allow for the possibility that the property might contain just a space or be missing, you can use code like:
{QUOTE{SET Val {={IF{={IF{DOCPROPERTY FirstProperty}= "Error!*" 1 0}+{IF{DOCPROPERTY FirstProperty}= " " 1 0}}= 1 0 10}+{IF{={IF{DOCPROPERTY SecondProperty}= "Error!*" 1 0}+{IF{DOCPROPERTY SecondProperty}= " " 1 0}}= 1 0 1}}}{IF{Val}= 11 "{DOCPROPERTY FirstProperty}, {DOCPROPERTY SecondProperty}" {IF{Val}= 10 {DOCPROPERTY FirstProperty} {IF{Val}= 1 {DOCPROPERTY SecondProperty}}}}}

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top