Using VBA to automate a new form in Word

L

Larry

I am trying to create a registration form that others can
fill in by using checkboxes and dropdown boxes. I can
get my results of these into text boxes; however I can
not get my code to add up the contents of several text
boxes to work. Can anyone point me in the right
direction? I try to use Microsoft help; however I can
not come up with the words that match Microsoft. I can
not find any examples or help.
 
J

JulieD

Hi larry

if you're trying to "add text" then you need to convert the text to a number
e.g.
TextBox3 = Val(TextBox1) + Val(TextBox2)

or
dim youranswer as long (no decimals or double - if you want decimals)
youranswer = Val(TextBox1) + Val(TextBox2)

hope this helps

regards
JulieD
 
L

Larry

I tried adding val and it still will not work. Here is
my vb code and one of the macros that call it. All of
the other macros work except for adding up the results. I
am going to try putting a button on the form to manually
call macSKTotal.

Thanks, Larry



Sub macSKTotal()
'
' macSKTotal Macro
' Macro created 6/16/2004 by Larry A. Kiser
'
Dim myAnswer As Double

myAnswer = Val(ActiveDocument.FormFields
("SKRegistrationFee").Result) _
+ Val(ActiveDocument.FormFields
("SKLadiesTickets").Result) + Val
(ActiveDocument.FormFields("SKBanquetCost").Result) _
+ Val(ActiveDocument.FormFields
("SKSpouseBanquetCost").Result) + Val
(ActiveDocument.FormFields("SKOtherGuestCost").Result)
ActiveDocument.FormFields("SKTotal").Result = myAnswer
End Sub
______________________________________________-

Sub macNumberOfSKLadies()
'
' macNumberOfSKLadies Macro
' Macro created 6/16/2004 by Larry A. Kiser
'
ActiveDocument.FormFields("SKLadiesTickets").Result =
ActiveDocument.FormFields("NumberOfSKLadies").Result *
LadiesCost
macSKTotal
End Sub
 
J

JulieD

Hi Larry
______________
Dim myAnswer As Double

myAnswer = Val(ActiveDocument.FormFields("text1").Result) _
+ Val(ActiveDocument.FormFields("text2").Result)

ActiveDocument.FormFields("text3").Result = myAnswer
___________
works for me ... i'm not sure if someone else has a better idea, but i would
put a message box either before or after the myanswer= line that does
something along the lines of this:
MsgBox "text 1 = " & ActiveDocument.FormFields("text1").Result & " text
2 = " & ActiveDocument.FormFields("text2").Result

in this way you can check the values returned from each of your formfields
and see if something is amiss

let us know how you go

Cheers
JulieD
 

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