Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

New to VBA - Calculation Validation?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TomorrowsMan - 21 Mar 2006 17:50 GMT
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!
Greg - 21 Mar 2006 19:35 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.