none
Error when calculating form fields RRS feed

  • Question

  • Hi.

    I have made an add-in for Word 2010. The Add-in places form-fields with amount, price pr. unit, subtotal (amount * price) and total price (subtotal + subtotal1 + ...).

    Is have been working OK till now, but now it is quoting the subtotal twice (SubtotalSsubtatal).

    How do I fix this???

    Bgr, Steffen

    Thursday, November 14, 2013 10:11 AM

All replies

  • This is a long-standing known bug with calculation formfields that get their input from other calculation formfields. The solution is to not use them; instead, use formula fields. To create one, press Ctrl-F9 to create an empty pair of field braces (i.e. { }). Then type your formula between them (e.g.{=subtotal + subtotal1 + ...}) and add whatever formatting switches you require.

    To create such a field programmatically, you'd use code like:

    With Selection 'or some specified range
      .Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, _
        Text:="=subtotal + subtotal1 + ...", Preserveformatting:=False
    End With


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, November 14, 2013 10:26 AM
  • Hi Paul.

    Thank you for the solution but it is not working. It still quotes the number twice.

    Steffen 

    Thursday, November 14, 2013 10:37 AM
  • It doesn't when I use it. Are you sure you deleted the offending formfield?

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, November 14, 2013 10:57 AM
  • Try to have a look at this file: https://dl.dropboxusercontent.com/u/28273423/FormField.docx

    The field a_0, p_0 and i_0 is created by one macro a it's working. Then I run a other macro for the Total.

    I have tried your macro on the document.

    See my program files:

    https://dl.dropboxusercontent.com/u/28273423/TekstBlok.bas and https://dl.dropboxusercontent.com/u/28273423/sum.bas

    Steffen

    Thursday, November 14, 2013 11:51 AM
  • I can't see anything approximating a formula field such as I suggested in either your document or your code.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, November 14, 2013 12:17 PM
  • The add-in: https://dl.dropboxusercontent.com/u/28273423/Varenr.dotm

    and the word document: https://dl.dropboxusercontent.com/u/28273423/108B02%2004204.docx

    Steffen

    Thursday, November 14, 2013 12:21 PM
  • This time, I still can't see anything approximating a formula field such as I suggested in your document. In the template, though, there is one instance of it in your code (the nysum sub in the test_mode module) but even then I can't see that being called anywhere. In the nysum sub, the field code is '=i_0', but should be '=a_0*p_0' so you're not referencing the calculation formfield. Alternatively, you could use 'REF i_0', but then you'd end up having to nest ref fields inside formula fields.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, November 14, 2013 1:06 PM
  • Hi Paul.

    Thank you for your replies. I think that I need to re-code the add-in so I use the fields that you suggested.

    Do you know why this error occurs? The add-in have been working without problems for almost a year.

    Steffen

    Thursday, November 14, 2013 1:31 PM
  • As I said in my first post:
    This is a long-standing known bug with calculation formfields.
    I do not know how your addin managed to work so long without it showing.


    Cheers
    Paul Edstein
    [MS MVP - Word]


    • Edited by macropodMVP Thursday, November 14, 2013 8:46 PM
    Thursday, November 14, 2013 8:46 PM