Thread Tools Display Modes
  #1   Report Post  
JR042 JR042 is offline
Junior Member
Posts: 1
Default Calculations with possible null value fields

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

I can use IF statements to test which fields have null values first, and then only perform the relevant calculation on those that don't have null values but when the number of fields in the calculation is higher than two, the number of permutations gets a bit too complex. I may have to do this for a calculation involving 12 fields so I'd rather avoid this kind 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 = 0 and the calculation works without IFs, but I have no choice but to use a txt file (there are more than 255 fields, which I believe is the max you can have in Excel - there may be other reasons for using txt which I don't know as I'm not responsible for it and would have difficulty having this changed). I can't manipulate the data source myself but I am 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 simplify the above by showing only the logic, rather than the actual code, but I'm quite new to programming so if there is a better solution, please could you show the full code?

Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Null values in word 2003 calculations Lenny Tables 0 September 10th 09 07:33 PM
Calculations in text form fields kmewing Microsoft Word Help 8 February 4th 09 05:06 AM
Calculations in Form Fields not working Jeff Doby Microsoft Word Help 2 March 28th 08 07:10 PM
Help! Form fields in table and calculations! R.P.McMurphy Microsoft Word Help 6 December 19th 05 12:38 PM
Calculations in form fields KathyHL Microsoft Word Help 1 June 18th 05 01:46 PM

All times are GMT +1. The time now is 07:26 AM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.

About Us

"It's about Microsoft Word"