Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculations in word

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I have 5 text boxes where a user could enter numbers in the first four. I want to put the total of the numbers they entered in the fifth textbox devided by the number of text boxes they entered.
Ex

Textbox 1: 10
Textbox 2: 10
Textbox 3:
Textbox 4:

Textbox 5: 10 (10+10 = 20 / 2 (number of textboxes with enters is 2))

How would I do this in Microsoft Word.
 
Hi there,

I've had a similar problem in the past when users have been too cheap to buy excel :p

You must use the text fields from the Forms toolbar for this to work.
Add your 5 text fields, go into the properties of the fifth field, select Type as Calculation and enter the following as the Expression:

=(Text1+Text2+Text3+Text4)/(if(Text1,1,0)+if(Text2,1,0)+if(Text3,1,0)+if(Text4,1,0))

Now, go into the VBA module, add a module and put the following code in:

Sub UpdateFields()
ActiveDocument.Fields.Update
End Sub

Close the VBA module, go into the properties of the first 4 text fields and select the UpdateFields macro as the Exit macro.

Now lock the form and all should work as you expect.

This looks like a messy solution.. and it is.. but it does the job.. anyone else??

Dave.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top