Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Lounger
    Join Date
    Jun 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form fields that calculate (2002)

    I'm designing a form in Word 2000 or later that contains several numeric fields and several fields that perform calculations based on the numeric fields. I cannot find any information on the syntax for calculations in form fields. Also, I would be interested in a formula that gives different results depending on the results of calculations in other fields. Does this require writing code?

    Thanks in advance, Karen

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form fields that calculate (2002)

    Hi Karen:
    Calculations start with an = sign, so the general syntax is:
    {= bookmark operator bookmark} where the curly braces are inserted with Ctrl+F9, not typed. In addition to normal +, -, etc. there are functions like SUM (above). Press F1 for the Help menu & search for formula & you will be able to find all the operators & functions.
    Cheers,

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form fields that calculate (2002)

    Each form field has a bookmark; you can refer to this bookmark in a formula. To make sure the formula is updated automatically, tick "Calculate on Exit" in the properties of the form field.

    Formulas are also fields, but not form fields; you insert them using Insert | Field..., or by typing Ctrl+F9 to insert field brackets { } (don't type the brackets yourself) and inserting the field code between them.

    Say that you have two form fields that are set to contain numbers. The associated bookmarks are Num1 and Num2. The following simple formula displays the product of the numbers (again, don't type the brackets yourself):

    { = { Num1 } * { Num2 } }

    If you want to perform conditional calculations, use the IF field. Example: if Num1 > 10, you want to add Num2 to Num1, otherwise, you want to subtract Num2 from Num1. Here is the field code:

    { IF { Num1 } > 10 { = { Num1 } + { Num2 } } { = { Num1 } - { Num2 } } }

    See the online help for information about the IF field and about the = (Formula) field. The latter has a list of functions you can use in formulas, such as SUM and MAX. If you want to see really advanced use of formulas and fields, download macropod's <!post=Date Calculations in Word,249902>Date Calculations in Word<!/post>.

  4. #4
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form fields that calculate (2002)

    If you have a form with multiple fields (bookmarks), how do you see the name of the bookmark? Is it possible to fill in one field and have that value appear elsewhere in the document? If so is it simply a formula of =value(bookmarkname) or similar?

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Form fields that calculate (2002)

    Hi Hans,

    It's even simpler than that. Try:
    {=Num1*Num2}
    That's right, you don't need to use REF fields to refer to the bookmarks used in a calculation!

    Cheers
    PS: For what it's worth, I'm attaching a draft of a field maths document, similar to the date calc one.
    Attached Files Attached Files
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Form fields that calculate (2002)

    I'm not a fields expert, but this is my understanding:

    > If you have a form with multiple fields (bookmarks), how do you see the name of the bookmark?

    It is listed in the form field's properties dialog.

    > Is it possible to fill in one field and have that value appear elsewhere in the document? If so is it
    > simply a formula of =value(bookmarkname) or similar?

    You generally use a REF field. Try Insert>Field...>Ref and check out all your options.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form fields that calculate (2002)

    Wow! That's impressive! I'm sure many people will find it useful.

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form fields that calculate (2002)

    I agree with Hans. It is impressive. Since it's a draft, I would suggest version numbers (like you did with the DateCalc.doc). I would also define what "ve" stands for, although the context in your attachment makes it obvious. <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

  9. #9
    New Lounger
    Join Date
    Jun 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form fields that calculate (2002)

    I'm new to this posting stuff. Is this the correct way to add more to the thread? I just clicked Respond to this Post.

    I found an excellent book on form fields. It's Using MS Office Word 2003 by Bill Camarda. It goes into a lot of detail and has good examples

    I did some debugging and I think my problem is that one of the fields used in the calculation is a dropdown with choices 1, 2, 3, 4, and 5. I made the first choice in the dropdown 'Choose one' so that would be the default and make sure someone didn't accidentally skip that question. I think the reason my formula wouldn't work is that I put TEXT in the choices instead of just numbers.

    Thanks for all the input. I learned a lot from your responses.
    Karen

  10. #10
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form fields that calculate (2002)

    Hi Karen:
    When the new information relates to the original question, as yours did, responding in the same thread is appropriate, even preferred. And in case we neglected to say so before, "Welcome to the Lounge".

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form fields that calculate (2002)

    Hi macropod:
    This macro doesn't work in Word 2000, as I get a message that "Method or data member not found" for .Name. Is there a way around that for Word 2000?
    Thanks,

  12. #12
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Form fields that calculate (2002)

    Oops,

    Wrong value in Dim: should have been 'Bookmark', not 'Field'

    Original post updated.

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  13. #13
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Form fields that calculate (2002)

    Hi Don,

    You can see bookmark names via Insert|Bookmark, but that doesn't show you their values. You can see any bookmark's value by using a REF field to display it, as in:
    {REF BkMrk} or, more simply, {BkMrk}
    where the field braces '{}' are created as a pair via Ctrl-F9. After typing the bookmark name, press F9 to display the field's results.

    Another way of listing bookmarks and their values is to run a macro like the following, which generates a list of all bookmarks at the end of the active document, and displays their contents:

    Sub ListBkMrks()
    Dim oBmk As Bookmark, oBkMrk
    If ActiveDocument.Bookmarks.Count > 0 Then
    For Each oBmk In ActiveDocument.Bookmarks
    With Selection
    .EndKey Unit:=wdStory
    .InsertAfter vbCrLf & oBmk.Name & " "
    .EndKey Unit:=wdStory
    oBkMrk = ActiveDocument.Fields.Add(Range:=Selection.Range, Text:=oBmk.Name, PreserveFormatting:=False)
    End With
    Next oBmk
    End If
    End Sub

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  14. #14
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form fields that calculate (2002)

    Hi Macropod,

    I think too that this is a very nice piece of work. <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>
    Provided your Windows is configured to use "," for grouping on thousands and "." for decimals, that is. But in Holland it's the other way around, so I get syntax errors all over the place in my Dutch version of Word 2003. <img src=/S/weep.gif border=0 alt=weep width=21 height=16>
    Is there a simpel way to make the formulae behave correctly indepent of this Windows configuration? Or is that only possible by replacing every "," with "." an vice versa?

  15. #15
    New Lounger
    Join Date
    Jun 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form fields that calculate (2002)

    I am still having problems with the form fields:
    I want to have a formula like this: {=JKRank * JKScore*100}

    JKRank is a percent.
    JKScore is a number ranging from 0 to 5 chosen from a dropdown.

    The formula works as long as I do not include JKScore
    It does not work when JKScore is included in any way in the formula, leading me to believe that you cannot put dropdown form fields in a formula.

    Right?

    I have also noticed that the formula typed into a calculation form field contains no {} but a formula entered manually with CTRL F9 has the {} around each bookmark cause that's the way I entered it. (The latter formula works but of course it doesn't calculate automatically.) Does this explain why the calculation form field doesn't work?

    As a test, I manually entered with CTRL F9 the formula {=percent*score} and it did not work, whereas {={percent}*{score} } did work.

    Thanks, Karen

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •