Check box used to force a calculation

D

Dawn Rhoads

I have a form that calculates a fee total to be paid. There are about 20
subtotals throughout the document. At one point, there is a checkbox. You
check it if you are entitled to a lower rate and the form should take the
subtotal immediately above it (bookmarked "sub8") and reduce it by 1/2 and
put the result in a field (bookmarked "sub9"). If the box isn't checked, the
sub9 field should either be blank or say 0.00.

Does anyone know a way to make Word do the calculation automatically when
the check box is checked? It's the one spot on our form that the user has to
stop and get their calculator out and manually type a result.

I am a beginning-intermediate user of macros, but I only know how to record
them or to paste in sample code, so if it's a macro solution I may need a
little extra guidance in getting it to work.

Thanks in advance for any ideas anyone has!
 
D

Doug Robbins

Run a macro containing the following code on exit from the checkbox (assumed
to be "Check1")

With ActiveDocument
If .Formfields("Check1").Checkbox.Value = True then
.Formfields("sub9").Result = .Formfields("sub8").Result*.5
Else
.Formfields("sub9").Result = Format(0, "0.00")
End If
End With

--
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
 
D

Dawn Rhoads

Thanks Doug, works great!

For anyone else who might be interested in this: one thing I had to figure
out, is that I needed to use a "text form field" for my subtotal field. We
had used the other kind of field -- not sure the terminology, but it's the
kind created by using the "Insert/Field" menu, and choosing the "=(formula)"
field off the list. This kind of field produced an error when running the
macro, saying it couldn't find the requested field.

But if I instead used a "text form field" (from the "forms" toolbar) I can
set the "type" to be "calculation" and then put in my formula and put in the
"sub8" bookmark in the field dialog box. You can uncheck the box for
"fill-in enabled" so the user doesn't have to tab through the field.

Turns out, I think this is a better method of inserting those calculation
fields, so I'm doubly glad Doug showed me this macro!

Thanks again for your help, Doug, appreciate it!
 

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