View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default conditional field layouts

Broadly speaking, you can use IF fields to do some of this. For example
suppose you have two address lines, and if address2 is blank you want

address1
suburb
city postcode

but if it is non-blank you want

address1
address2
suburb, city postcode

then you can use

{ MERGEFIELD address1 }
{ IF "{ MERGEFIELD address2 }" = ""
"{ MERGEFIELD suburb }
{ MERGEFIELD city } { MERGEFIELD postcode }"
"{ MERGEFIELD address2 }
{ MERGEFIELD suburb }, { MERGEFIELD city } { MERGEFIELD postcode }" }

(or in this case

{ MERGEFIELD address1 }
{ IF "{ MERGEFIELD address2 }" = ""
"{ MERGEFIELD suburb }
" "{ MERGEFIELD address2 }
{ MERGEFIELD suburb }, " }{ MERGEFIELD city } { MERGEFIELD postcode }

etc. All the {} need to be the special "field code braces" that you can
insert using ctrl-F9.

Determining a layout based on the amount of text would be more difficult
- I don't think there's an obvious way to compare actual text width
unless you are using fixed-width fonts, but you may be able to get
character counts from your data source (depending on what it is) or do
comparisons using "wildcards" to determine character counts.

Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Peter wrote:
I'd appreciate help for setting alternate name and address layouts in a mail
merge. For example, the default layout might have these fields on 2 lines:

Suburb
City & PostCode

But if there is extra information in the full address, those fields might
need to go all on one line to meet constraints of page size, postal regs etc:

Suburb & City & PostCode

Any tips on how to do this would be appreciated.