View Single Post
  #2   Report Post  
Posted to microsoft.public.word.tables
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default summing a column of values from dropdown boxes

The macro is the right idea, but you need to fix the syntax:

ActiveDocument.FormFields("ColTotal").Result = _
Val(ActiveDocument.FormFields("Dropdown1").Result) + _
Val(ActiveDocument.FormFields("Dropdown2").Result)

Note that there's a space before each underscore at the ends of the
first two lines. That's required.

For the ColTotal field, use a text form field. In its Properties
dialog, uncheck the box for "Fill-in enabled" to prevent users from
typing in a number different from the sum of the dropdowns.

It makes no difference to the macro whether the fields are in a table
or in plain text. But the table, if autofit is turned off, will
prevent other text around the form fields from moving when the amount
of text in the fields changes.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On 6 Oct 2006 15:47:33 -0700, wrote:

Word 2000: I have a table with two form field dropdown boxes in a
column where the user selects a single value from the dropdown box in
each. I want to show the resulting sum total for the two boxes in the
bottom cell of the column.

I've tried inserting a table formula (=b1+b2) -- doesn't work; it's
always equal to zero even though I have checked the "Calculate on exit"
box in b1 and b2 properties.

I've tried writing a macro:
ActiveDocument.FormFields("Coltotal").Result =
ActiveDocument.FormFields("Dropdown1").Value +
ActiveDocument.FormFields("Dropdown2").Value
This also doesn't work even though I've set "Run macro on exit" in b1
and b2. Here I'm also not sure how to properly define the Coltotal
field -- what type of field is it? Dropdown doesn't seem right, how do
I create the appropriate field type in the table cell?

Would the answer be any different if the dropdown boxes and result box
were not inside a table?

Any help appreciated. Thx.

/Bill