No, that won't help.
What else did you change so that you can use 100 instead of
1.0? What is the data type and Size of the [Percent of
Composition] field in the table? This is important because
it will affect the code below.
Here is a completely different way to calculate the sum that
allows the code to check the total. Put this code in the
percent text box's AfterUpdate event:
Dim TotalPercent As Long
TotalPercent = 0
With Me.RecordsetClone
.MoveFirst
Do Until .EOF
TotalPercent = TotalPercent + Nz(![Percent of
Composition], 0)
.MoveNext
Loop
End With
Me.tboxpercofcomptotal = TotalPercent
Then the Form's Before Update event would be:
If Me.tboxpercofcomptotal > 100 Then
MsgBox "Too high of percentage. Please correct"
Cancel = True
End If
Once the total is calculated in the text box's AfterUpdate
event, the check for the total > 100 could also be done for
a more immediate check.
--
Marsh
MVP [MS Access]
[email protected] wrote:
You're correct, the textbox that does the total doesn't add up before
the code gets executed. If I type in 100 for 100%
this works fine, but if I change that to 102 the error pops up and
when I retype in 100 to make it correct, it still recognizes that as
over 100% because the total textbox hasn't recalculated before the
msgbox stating that it's too high goes off. Make sense?
What if I put this before the code you gave me?
If Me.tboxpercofcomptotal >= 100 Then
exit sub
I guess the issue is that the total textbox needs to total up before
the code gets executed, right?
[]
You can try adding the line:
Me.percenttextbox.Undo
to undo the change in the percent text box,
or, the line:
Me.Undo
to undo all the edits to the current record.
However, I don't think it will help. The issue is that the
calculation is done asynchronously from the form updates and
the code we're using. That means that the total percent
**might** not be recalculated by the next time the code
checks it.
You've come a long way in just a couple of months, but this
is a very tricky issue that can only be resloved completely
by doing the sum in a VBA procedure.
If neither Undo does the job and if the values in the
debugging msgbox demonstrates the above issue, post back and
I'll put together an alternate approach.
[email protected] wrote:
I got it work, the msgbox comes up but after it states that the
percentage is to high, I can't change the percentage numbers back to
make it 100%. Instead of cancel is there away to do undo last action?