How to trigger a macro on a calcuated form field?

C

ChristineP

I have a purchase order document with form fields to calculate quantity x
unit price to get an extended price. There is a calculated field at the
bottom called Total that sums all the extended prices above it. If the
TotalPrice is >100, then I want to change a checbox value to true. Here's the
code for the macro:

If ActiveDocument.FormFields("TotalPrice").Result > "100.00" Then
ActiveDocument.FormFields("Finance").CheckBox.Value = True
Else
ActiveDocument.FormFields("Finance").CheckBox.Value = False
End If

Trouble is, the macro can't go into either the ExtenedPrice or Total field's
OnEntry or OnExit event because they are calculated fields that don't get any
focus. Where should the macro go to get it to trigger.

Any speedy help will be appreciated!
 
T

Tony Jollans

Hi Christine,

If you set your macro as an Exit Macro on the Fields which are updateable
(Quantity, Unit Price) it should run whenever any of them change.
Unfortunately the updates done by "Calculate On Exit" aren't done until after
the macro is run so you need to force updates before you do your checking.

I note you check your result against a string value of "100.00". A string
value of, say, "2" will come out greater than this. Assuming this to be an
error, I have changed it.

ActiveDocument.Fields.Update
If ActiveDocument.FormFields("TotalPrice").Result > 100 Then
ActiveDocument.FormFields("Finance").CheckBox.Value = True
Else
ActiveDocument.FormFields("Finance").CheckBox.Value = False
End If

Enjoy,
Tony
 
G

Graham Mayor

You can achieve this without a macro if you are not using the check box for
any other purpose than a visual indication

{ IF { REF TotalPrice } > 100 "{ AUTOTEXT "Checked Box" }" "{ AUTOTEXT
"Unchecked Box" }" }

Where the two autotexts are checked and unchecked box characters - see
http://www.gmayor.com/Macrobutton.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - 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