fields adding up to 100%

S

Sheri

I have a form with three fields that contain percentages.
I need the field to add up to 100%. If they don't add up
to 100% I don't want the user to go forward and have some
type of message pop up. When they add up to 100% the user
goes on to the next question.

I'm using Office 2003. Thanks for the help !
 
A

Allen Browne

Use the BeforeUpdate event procedure of the *form* to see if the 3
percentages add up to 1 (i.e. 100%).

Because you are dealing with fractional values, it is possible that the sum
will not be exactly 1, so the example below warns the user if the difference
is more than a tenth of a percent:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If 1 - Abs(Me.F1 + Me.F2 + Me.F3) > .001 Then
Cancel = True
MsgBox "Doesn't add up."
End If
End Sub
 
Top