Conditional create table

F

furiouscanis

Hi All

I'm a complete beginnier at mail merges so please be gentle.

I've inherited a mail merge were we want to have a formatted table
only if there is data present. The number of rows in the table
(excluding header) can be between 0 and 3, if its 0 then dont show the
table, otherwise only the rows with data.

Any help or pointers would be very much appreciated.

cheers

Keith
 
P

Peter Jamieson

How to do this depends on precisely how you determine how many rows you
need and what should be in them. If te table only relates ot a single
data source, then it would typically be something like
a. If fielda is non-blank, insert a row containing fielda
b. if fieldb is non-blank, insert a row containing fieldb
c. if fieldc is non-blank, insert a row containing fieldc

In that scenario, there are 7 possible tables that actually contain
anything and you could
a. insert a nested IF field that contains each of the 7 tables, e.g.

{ IF "{ MERGEFIELD fielda }" = ""
"{ IF "{ MERGEFIELD fieldb }" = ""
"{ IF "{ MERGEFIELD fieldc }" = "" ""
"put the table and fields for a table with a fieldc row only here" }"
"{ IF "{ MERGEFIELD fieldc }" = ""
"put the table and fields for a table with a fieldb row only here"
"put the table and fields for a table with fieldb and fieldc here" }"
"similar stuff for the case where fielda is non-blank" }

All the {} have to be the special field code braces that you can insert
using ctrl-F9. You can toggle bewteen field codes and results using
alt-F9. You can put text, complete tables, and field codes inside the IF
"results" as I have indicated.

Probably slightly simpler in some respects would be to calculate a
"table number", e.g. where fielda <> "" counts 4, fieldb <> blank counts
2 and fieldc <> "" counts 1. Then table 6 would be the table with
non-blank fielda and fieldb, but blank fieldc.

You could do that as follows:

{ SET tablenumber { =4*{ COMPARE "{ MERGEFIELD fielda }" <> "" }
+ 2*{ COMPARE "{ MERGEFIELD fieldb }" <> "" }
+ { COMPARE "{ MERGEFIELD fieldc }" <> "" } }

Then you can have a separate IF for each table and avoid nesting, e.g.

{ IF { REF tablenumber } = 1 "table and fields for fieldc only" ""
}{ IF { REF tablenumber } = 2 "table and fields for fieldb only" ""
}{ IF { REF tablenumber } = 3 "table and fields for fieldb and fieldc
only" ""
}

etc.

Of course /your/ conditions could be more complex (IMO separating a
calculation based on the conditions from the actual business of the
layout is probably even more useful in that case) or you may be getting
data from multiple records, in which yu would need a rather different
approach.

Peter Jamieson

http://tips.pjmsn.me.uk
 
F

furiouscanis

Hi Guys

Thanks for the posts. It was a little more complicated, the data came
from a excel spreadsheet and was split horizontally rather than
vertically. In the end i went with using VBA to query the mergefields
to see if they contained a value, used that to work out the number of
rows needed, and then build the table programmatically. Theres
probably a better way, but that took less time to learn. Ah, the
whooshing sound of deadlines.

cheers

keith
 

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