View Single Post
  #1   Report Post  
Posted to microsoft.public.word.tables
Fred Fred is offline
external usenet poster
 
Posts: 6
Default Display plus or minus signs on calculated table field

I wasn't sure whether this query counted as a table query or a VB
query, so have posted here first.

Using Word 97, I have a word table, that is set to protected (Forms).
In the table there are, amongst others, 2 columns of dates and a third
column which I need to calculate the difference between the dates in
the other two columns.

I have defined the date columns with a Type of Date, both have bookmark
names ITarg1 ...n and CTarg1 ...n the third column is has a Type of
Number, a bookmark of MSDD1 ...n and a format of +#,##0

On exit from the CTarg column I run a macro (DD_MSDD1 ...n) to
calculate the difference and put the result in the third column.

Sub DD_MSDD1()
MilestoneDateDiff "1" 'call to common routine to calc diff for MSDD1
End Sub

Sub MilestoneDateDiff(DD)

Initial = DateValue(ActiveDocument.FormFields("ITarg" & DD).Result)
Current = DateValue(ActiveDocument.FormFields("CTarg" & DD).Result)
days = Format(Current - Initial, ("+#,##0 ;-#,##0"))
ActiveDocument.Unprotect
ActiveDocument.FormFields("MSDD" & DD).Result = days
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Sub

What I need to achieve is the difference figure in the third column to
display either as +ddd or -ddd, so far all I can achieve is ddd or
-ddd. I have tried various formats, both within the vb and the cell
format to no avail, ending up with, "(+14)" when there is a negative
difference, (go figure !) or "+28" when there is a positive difference
when I had set the MSDD1 cell with a format of +#,##0;(-#,##0)

I would also like to introduce some degree of checking that there are
values in both ITarg and CTarg cells, if at all possible.

Can anyone help me out with this problem please ?

Thanks and regards
Fred