New to VBA - Calculation Validation?

T

TomorrowsMan

Hi there,

I am trying something I think is simple, but can't get it to work (I am
very new at using Word for form field calculations, but my office does
not want to use Excel).

I have five fields that are percentages (Obj11-Obj15). The user enters
amounts into up to five of them -- so, they could enter numbers into
only four, as long as the total field (Total1) equals 100% when they're
done.

If the calculation field does not equal 100%, I would like to have a
popup or notification that warns the user that the total is invalid.
So, in my perfect world I would have the notification send them back to
the first of the five fields after they click off of it, but I can't
get to the validation -- first I need to figure out how to validate
that the Total1 calculation field equals 100%.

Thanks!
 
G

Greg

TodaysQuestioner,

Validating "Total" and creating the popup/redirection are no problem:

Sub VerifyTotal()
Dim oFFld As FormFields
Set oFFld = ActiveDocument.FormFields
If Val(oFFld("Total").Result) = 100 Then
MsgBox "Good to go."
Else
MsgBox Val(oFFld("Total").Result) & " is <> than 100."
oFFld("Text1").Range.Select
End If
End Sub

The problem to solve is "when and how" you want the validation
performed. Obviously you don't know in advance if the user is going to
use 1 field, 5 fields, or something in between. That said, you can do
it real time as the fields are filled in. Since the "Total" field is
most likely a calculation field the user never "enters" or "exits" the
field. You could run the above code on entry to a field after "Total"
but if the user uses a mouse, he or she may mouse click from field to
field and never avoid that field.

Good luck
 

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