Calculations with possible null value fields

J

JR042

I'm trying to perform the following calculation in Word 2007 mailmerge
using a txt file (with line return record delimiters and vertical bar
field delimiters) as my data source but I keep getting a syntax error i
any of the fields have null values:
R1 + C1 + M1

I can use IF statements to test which fields have null values first, an
then only perform the relevant calculation on those that don't have nul
values but when the number of fields in the calculation is higher tha
two, the number of permutations gets a bit too complex. I may have to d
this for a calculation involving 12 fields so I'd rather avoid this kin
of logic:

If R1 AND C1 AND M1 = null, total = ‘0’
Else, If R1 AND C1 = null, total = M1
Else, If R1 AND M1 = null, total = C1
Else, If R1 = null, total = C1 + M1
Else, If C1 AND M1 = null, total = R1
Else, If C1 = null, total = R1 + M1
Else, If M1 = null, total = R1 + C1
Else, total = R1 + C1 + M1

If I use Excel as the data source, somehow Word seems to assume null =
and the calculation works without IFs, but I have no choice but to use
txt file (there are more than 255 fields, which I believe is the max yo
can have in Excel - there may be other reasons for using txt which
don't know as I'm not responsible for it and would have difficult
having this changed). I can't manipulate the data source myself but I a
looking at having the null values changed to zeros, if possible.

Failing that, is there a simpler way to do this? I've tried to simplif
the above by showing only the logic, rather than the actual code, bu
I'm quite new to programming so if there is a better solution, pleas
could you show the full code?

Thanks
 
L

Lisa Wilke-Thissen

Hi,
I'm trying to perform the following calculation in
Word 2007 mailmerge, using a txt file (with
line return record delimiters and vertical bar |
field delimiters) as my data source but I keep getting
a syntax error if any of the fields have null values:
R1 + C1 + M1

You should use Excel as a data source. Excel 2007 offers more than
16,000 columns
(http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP010073849.aspx).
I can use IF statements to test which fields have
null values first,

Null values means "empty" fields? Convert the txt-file to Excel.
Otherwise use Ctrl + H (Replace) to fill empty fields with zero.
 

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