Formula to calculate sum based on drop down form fieldsin Word...continued

P

pedy g

Hi,

In saw this post and it helped me a bit:

http://www.eggheadcafe.com/software/aspnet/31264679/formula-to-calculate-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
 
J

Jean-Guy Marcil

pedy g said:
Hi,

In saw this post and it helped me a bit:

http://www.eggheadcafe.com/software/aspnet/31264679/formula-to-calculate-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!
;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top