Calculations if Form Fields

N

Nigel

I am trying to calculate some fields in a word form, the end result should be
that one field (Totalfee) is the total of 2 other fields (A1 + A2)

here is the code I am using

Sub Stalls()

Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("Stalls").Result = vstalls
ActiveDocument.FormFields("stallcost").Result = vstalls * 45
ActiveDocument.FormFields("Facilities").Result = Stallcost + plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1
End Sub


Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("plug").Result = vplugs


ActiveDocument.FormFields("plugcost").Result = vplugs * 30
ActiveDocument.FormFields("Facilities").Result = Stallcost + plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1


End Sub

Sub Fees()

Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("A1").Result = vfees

ActiveDocument.FormFields("TotalFee").Result = A1 + A2

End Sub


I cannot get it to do the totals - any suggestions?

Thanks in advance
 
M

macropod

Hi Nigel,

Try:
Sub Stalls()
Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("Stalls").Result = vstalls
.FormFields("stallcost").Result = vstalls * 45
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End With
End Sub

Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("plug").Result = vplugs
.FormFields("plugcost").Result = vplugs * 30
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Sub Fees()
Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("A1").Result = vfees
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Cheers
 
N

Nigel

I changed it to the following and it will fill in the subtotal fields
(A1,stallcost plugcost) but the value it wants to put in the total fields is
70 or combinations of that

Sub Stalls()
Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("Stalls").Result = vstalls
.FormFields("stallcost").Result = vstalls * 45
.FormFields("Facilities").Result = .FormFields("Stallcost") +
..FormFields("plugcost")
.FormFields("A2").Result = .FormFields("Facilities")
.FormFields("TotalFee").Result = .FormFields("A2") + .FormFields("A1")
End With
End Sub

Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("plug").Result = vplugs
.FormFields("plugcost").Result = vplugs * 30
.FormFields("Facilities").Result = .FormFields("Stallcost") +
..FormFields("plugcost")
.FormFields("A2").Result = .FormFields("Facilities")
.FormFields("TotalFee").Result = .FormFields("A2") + .FormFields("A1")
End With
End Sub

Sub Fees()
Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("A1").Result = vfees
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("Facilities").Result = .FormFields("Stallcost") +
..FormFields("plugcost")
.FormFields("A2").Result = .FormFields("Facilities")
.FormFields("TotalFee").Result = .FormFields("A2") + .FormFields("A1")
End With
End Sub
 
N

Nigel

this is what is showing in the calculation field


Total Facilities Cost ttt.00



macropod said:
Hi Nigel,

Try:
Sub Stalls()
Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("Stalls").Result = vstalls
.FormFields("stallcost").Result = vstalls * 45
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End With
End Sub

Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("plug").Result = vplugs
.FormFields("plugcost").Result = vplugs * 30
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Sub Fees()
Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("A1").Result = vfees
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

Nigel said:
I am trying to calculate some fields in a word form, the end result should be
that one field (Totalfee) is the total of 2 other fields (A1 + A2)

here is the code I am using

Sub Stalls()

Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("Stalls").Result = vstalls
ActiveDocument.FormFields("stallcost").Result = vstalls * 45
ActiveDocument.FormFields("Facilities").Result = Stallcost + plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1
End Sub


Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("plug").Result = vplugs


ActiveDocument.FormFields("plugcost").Result = vplugs * 30
ActiveDocument.FormFields("Facilities").Result = Stallcost + plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1


End Sub

Sub Fees()

Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("A1").Result = vfees

ActiveDocument.FormFields("TotalFee").Result = A1 + A2

End Sub


I cannot get it to do the totals - any suggestions?

Thanks in advance
 
D

Doug Robbins - Word MVP

You cannot use as the input to a formfield calculation a formfield that is
itself the result of a formfield calculation.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Nigel said:
this is what is showing in the calculation field


Total Facilities Cost ttt.00



macropod said:
Hi Nigel,

Try:
Sub Stalls()
Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("Stalls").Result = vstalls
.FormFields("stallcost").Result = vstalls * 45
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End With
End Sub

Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("plug").Result = vplugs
.FormFields("plugcost").Result = vplugs * 30
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Sub Fees()
Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("A1").Result = vfees
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

Nigel said:
I am trying to calculate some fields in a word form, the end result
should be
that one field (Totalfee) is the total of 2 other fields (A1 + A2)

here is the code I am using

Sub Stalls()

Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("Stalls").Result = vstalls
ActiveDocument.FormFields("stallcost").Result = vstalls * 45
ActiveDocument.FormFields("Facilities").Result = Stallcost + plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1
End Sub


Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("plug").Result = vplugs


ActiveDocument.FormFields("plugcost").Result = vplugs * 30
ActiveDocument.FormFields("Facilities").Result = Stallcost + plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1


End Sub

Sub Fees()

Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("A1").Result = vfees

ActiveDocument.FormFields("TotalFee").Result = A1 + A2

End Sub


I cannot get it to do the totals - any suggestions?

Thanks in advance
 
N

Nigel

so is there any way around this?

Doug Robbins - Word MVP said:
You cannot use as the input to a formfield calculation a formfield that is
itself the result of a formfield calculation.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Nigel said:
this is what is showing in the calculation field


Total Facilities Cost ttt.00



macropod said:
Hi Nigel,

Try:
Sub Stalls()
Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("Stalls").Result = vstalls
.FormFields("stallcost").Result = vstalls * 45
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End With
End Sub

Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("plug").Result = vplugs
.FormFields("plugcost").Result = vplugs * 30
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Sub Fees()
Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("A1").Result = vfees
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

I am trying to calculate some fields in a word form, the end result
should be
that one field (Totalfee) is the total of 2 other fields (A1 + A2)

here is the code I am using

Sub Stalls()

Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("Stalls").Result = vstalls
ActiveDocument.FormFields("stallcost").Result = vstalls * 45
ActiveDocument.FormFields("Facilities").Result = Stallcost + plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1
End Sub


Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("plug").Result = vplugs


ActiveDocument.FormFields("plugcost").Result = vplugs * 30
ActiveDocument.FormFields("Facilities").Result = Stallcost + plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1


End Sub

Sub Fees()

Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("A1").Result = vfees

ActiveDocument.FormFields("TotalFee").Result = A1 + A2

End Sub


I cannot get it to do the totals - any suggestions?

Thanks in advance
 
D

Doug Robbins - Word MVP

Yes, in the final calculation refer to the individual formfields rather than
the formfield to the .Result of which they contribute.

I am not sure why you are using formfields in the first place. I would use
a userform.

See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Nigel said:
so is there any way around this?

Doug Robbins - Word MVP said:
You cannot use as the input to a formfield calculation a formfield that
is
itself the result of a formfield calculation.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Nigel said:
this is what is showing in the calculation field


Total Facilities Cost ttt.00



:

Hi Nigel,

Try:
Sub Stalls()
Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("Stalls").Result = vstalls
.FormFields("stallcost").Result = vstalls * 45
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End With
End Sub

Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("plug").Result = vplugs
.FormFields("plugcost").Result = vplugs * 30
.FormFields("Facilities").Result = Stallcost + plugcost
.FormFields("A2").Result = Facilities
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Sub Fees()
Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)
On Error Resume Next
With ActiveDocument
.FormFields("A1").Result = vfees
.FormFields("TotalFee").Result = .FormFields("A2").Result + _
.FormFields("A1").Result
End Sub

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

I am trying to calculate some fields in a word form, the end result
should be
that one field (Totalfee) is the total of 2 other fields (A1 + A2)

here is the code I am using

Sub Stalls()

Dim Message, Title, vstalls
Message = "Enter Number of Stalls required" ' Set prompt."
Title = "Stalls" ' Set title.
' Set default.
' Display message, title, and default value.
vstalls:
vstalls = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("Stalls").Result = vstalls
ActiveDocument.FormFields("stallcost").Result = vstalls * 45
ActiveDocument.FormFields("Facilities").Result = Stallcost +
plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1
End Sub


Sub plugins()
Dim Message, Title, vplugs
Message = "Enter Number of Plug Ins required" ' Set prompt."
Title = "Plug Ins" ' Set title.
' Set default.
' Display message, title, and default value.
vplugs:
vplugs = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("plug").Result = vplugs


ActiveDocument.FormFields("plugcost").Result = vplugs * 30
ActiveDocument.FormFields("Facilities").Result = Stallcost +
plugcost
ActiveDocument.FormFields("A2").Result = Facilities
ActiveDocument.FormFields("TotalFee").Result = A2+A1


End Sub

Sub Fees()

Dim Message, Title, vstalls
Message = "Enter Total Show Fees" ' Set prompt."
Title = "Show Fees" ' Set title.
' Set default.
' Display message, title, and default value.
vfees:
vfees = InputBox(Message, Title)


On Error Resume Next
ActiveDocument.FormFields("A1").Result = vfees

ActiveDocument.FormFields("TotalFee").Result = A1 + A2

End Sub


I cannot get it to do the totals - any suggestions?

Thanks in advance
 

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