Validating sum of fields in form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two fields in my data entry form and I want to validate that the sum
of the 2 fields is equal to 100 so I created a calculated field that sums the
2 and tried adding the validation rule >99.9 <101 but that doesn't work. I'm
sure there's a better solution that actually works. I appreciate the help for
what's probably a no- brainer for some of you out there.
 
A better way to do this would be to put a check in the Before Update event of
your form:

Dim sngFldTot as Single

sngFldTot = Me.txtField1 + Me.txtField2
If sngTot <> 100 Then
MsgBox "Total is " & sngFldTot & " Should be 100"
Cancel = True
Me.txtField1.SetFocus
End If
 
Thanks, a little typo in the If section (sngTot instead of sngFldTot) had me
stumped for a couple of minutes. I also didn't mention that I really needed
this for 2 calculated sums but I just added another variable and a second IF
statement based on your original and it seems to work just fine. Thanks for
the help.
 
Back
Top