Problem adding form fields

L

Louis

I have the addition of some form fields embedded in a case statement.

I finally have the totals appearing on the form, However the totals are
wrong.

For example if I add 12,233.00 + 12.11 +23.41, I get an answer of $47.52


Below is the code I am using.

Does anyone see what the problem is?
Thanks for your time
Lou


'Set tab to total charges for apartment.
Case "txtcharge8"
sTabTo = "txttotalcharges"


'Add list of charges
Dim c1, c2, c3, c4, c5, c6, c7, c8, tc, bd As Long
c1 = Val(ActiveDocument.FormFields("txtcharge1").Result)
c2 = Val(ActiveDocument.FormFields("txtcharge2").Result)
c3 = Val(ActiveDocument.FormFields("txtcharge3").Result)
c4 = Val(ActiveDocument.FormFields("txtcharge4").Result)
c5 = Val(ActiveDocument.FormFields("txtcharge5").Result)
c6 = Val(ActiveDocument.FormFields("txtcharge6").Result)
c7 = Val(ActiveDocument.FormFields("txtcharge7").Result)
c8 = Val(ActiveDocument.FormFields("txtcharge8").Result)
tc = Val(ActiveDocument.FormFields("txttotalcharges").Result)
bd = Val(ActiveDocument.FormFields("txtbalancedue").Result)

tc = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8
bd = tc

ActiveDocument.FormFields("txttotalcharges").Result = tc
ActiveDocument.FormFields("txtbalancedue").Result = tc
 
D

Doug Robbins - Word MVP

Hi Louis,

A calculation that is based on the .Result of a formfield that itself is a
calculation will not give the correct answer.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
L

Louis

Doug,

I am sorry, I do not understand what you mean. I changed the code so that
the code reads as follows. But I still can not get a correct total.
????????????????????

Lou

'Add list of charges

Dim c1, c2, c3, c4, c5, c6, c7, c8, tc, bd As Long

c1 = Val(ActiveDocument.FormFields("txtcharge1"))
c2 = Val(ActiveDocument.FormFields("txtcharge2"))
c3 = Val(ActiveDocument.FormFields("txtcharge3"))
c4 = Val(ActiveDocument.FormFields("txtcharge4"))
c5 = Val(ActiveDocument.FormFields("txtcharge5"))
c6 = Val(ActiveDocument.FormFields("txtcharge6"))
c7 = Val(ActiveDocument.FormFields("txtcharge7"))
c8 = Val(ActiveDocument.FormFields("txtcharge8"))
'tc = Val(ActiveDocument.FormFields("txttotalcharges"))
'bd = Val(ActiveDocument.FormFields("txtbalancedue"))

tc = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8
bd = tc

Val (ActiveDocument.FormFields("txttotalcharges") = tc)
Val (ActiveDocument.FormFields("txtbalancedue") = tc)
 
D

Doug Robbins - Word MVP

Hi Louis,

No, that won't work. Maybe the information that I gave you before is not
relevant to your particular case. The problem I was referring to is covered
in the Knowledge Base Article at
http://support.microsoft.com/default.aspx?scid=kb;en-us;211253

If we go back to your original post, probably what you should have is

'Add list of charges
Dim c1, c2, c3, c4, c5, c6, c7, c8, tc, bd As Long
c1 = Val(ActiveDocument.FormFields("txtcharge1").Result)
c2 = Val(ActiveDocument.FormFields("txtcharge2").Result)
c3 = Val(ActiveDocument.FormFields("txtcharge3").Result)
c4 = Val(ActiveDocument.FormFields("txtcharge4").Result)
c5 = Val(ActiveDocument.FormFields("txtcharge5").Result)
c6 = Val(ActiveDocument.FormFields("txtcharge6").Result)
c7 = Val(ActiveDocument.FormFields("txtcharge7").Result)
c8 = Val(ActiveDocument.FormFields("txtcharge8").Result)
ActiveDocument.FormFields("txttotalcharges").Result = c1 + c2 +
c3 + c4 + c5 + c6 + c7 + c8
ActiveDocument.FormFields("txtbalancedue").Result= c1 + c2 + c3
+ c4 + c5 + c6 + c7 + c8

But you can do this without using a macro by Formfield "txttotalcharges" and
"txtbalancedue" to calculation type formfields and inserting the following
formula

= txtcharge1 + txtcharge2 + txtcharge3 + txtcharge4 + txtcharge5 +
txtcharge6 + txtcharge7 + txtcharge8

and in the properties dialog for each of txtcharge1 thru txtcharge8, check
the calculate on exit box.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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