Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
pedy g pedy g is offline
external usenet poster
 
Posts: 1
Default Formula to calculate sum based on drop down form fieldsin Word...continued

Hi,

In saw this post and it helped me a bit:

http://www.eggheadcafe.com/software/...ulate-sum.aspx

macropod posted this fomula:

{={REF DropDown1}+{REF DropDown2}+{REF DropDown3}+{REF DropDown4}+{REF DropDown5}}

BUT, in a large document that contains a TOC it doesn't seem to work very well, almost as if it is not refreshing properly.

The I used this macro:

Sub AddDropDownResults()
Dim dDown1, dDown2 As Integer
' Get value of first drop down form field.
dDown1 = Val(ActiveDocument.FormFields ("DropDown1").Result)
' Get value of second drop down form field.
dDown2 = Val(ActiveDocument.FormFields("DropDown2").Result)
' Calculate results and place in Text1 form field
ActiveDocument.FormFields("Text1").Result = Str(dDown1 + dDown2)

End Sub

BUT again in a large document it reacts strangely. It basically scroll up & down every page that the macro is running in...

Any help would be greatly appreciated

Thanks

Pedy
  #2   Report Post  
Posted to microsoft.public.word.tables
Jean-Guy Marcil[_2_] Jean-Guy Marcil[_2_] is offline
external usenet poster
 
Posts: 373
Default Formula to calculate sum based on drop down form fields in Word...

"pedy g" wrote:

Hi,

In saw this post and it helped me a bit:

http://www.eggheadcafe.com/software/...ulate-sum.aspx

macropod posted this fomula:

{={REF DropDown1}+{REF DropDown2}+{REF DropDown3}+{REF DropDown4}+{REF DropDown5}}

BUT, in a large document that contains a TOC it doesn't seem to work very well, almost as if it is not refreshing properly.


Can you describe exactly what happens?

The I used this macro:

Sub AddDropDownResults()
Dim dDown1, dDown2 As Integer
' Get value of first drop down form field.
dDown1 = Val(ActiveDocument.FormFields ("DropDown1").Result)
' Get value of second drop down form field.
dDown2 = Val(ActiveDocument.FormFields("DropDown2").Result)
' Calculate results and place in Text1 form field
ActiveDocument.FormFields("Text1").Result = Str(dDown1 + dDown2)

End Sub

BUT again in a large document it reacts strangely. It basically scroll up & down every page that the macro is running in...


I do not undersatand.. can you elaborate? Again, what is it that you are
actually observing? How can the macro "scroll up & down every page" when it
is only concerned with three formfields?

The size of the document, or the fact that it has a TOC, should not have any
impact on this macro.

By the way, in VBA
Dim dDown1, dDown2 As Integer
means that dDown2 is declared as an Integer type and dDown1 is declared as a
Variant type.

You need:
Dim dDown1 As Integer, dDown2 As Integer
or
Dim dDown1 As Integer
Dim dDown2 As Integer
Also, the Integer type is not used anymore.
I believe the smallest memory unit the compiler will allocate is a Long. So,
when you declare Integers, the compiler has to internally convert them to
Longs. Might as well declare Longs from the get go!
;-)

Reply
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
What is the formula to calculate a percentage in a Word table? J Kimble Tables 3 July 4th 23 12:37 PM
Formula to calculate sum based on drop down form fields in Word KLane Tables 11 December 24th 08 07:52 PM
how to calculate formula in an office 2007 word table VATI Tables 1 March 22nd 08 07:12 AM
change color of cell based upon form drop down selection Tim Doyle Tables 1 October 27th 06 07:41 PM
formula to calculate form fill-in fields Gib Microsoft Word Help 1 February 5th 05 05:59 AM


All times are GMT +1. The time now is 04:37 PM.

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

About Us

"It's about Microsoft Word"