Calculation check does not work?

T

Tony Williams

I have a form that includes a tab control. I want to check that the total in
a control on page 3 of the tab control agrees with the total of another
control on page 2 when the form is closed. I have the following code in the
Before Update event of the total on page 3
Private Sub txtAdvTot_BeforeUpdate(Cancel As Integer)
If ([txtAdv0] + [txtAdv500] + [txtAdv1000] + [txtAdv5000] + [txtAdv10000] +
[txtAdv50000] + [txtAdv100000]) <> [txtAdvTot] Then
If MsgBox(" Column 1 does not add up" & vbCrLf & "It should be " & [txtAdv0]
+ [txtAdv500] + [txtAdv1000] + [txtAdv5000] + [txtAdv10000] + [txtAdv50000]
+ [txtAdv100000] & " - Do you want to accept the error?", vbYesNo,
"Calculation Error") = vbNo Then
Cancel = True

If ([txtAdv0] + [txtAdv500] + [txtAdv1000] + [txtAdv5000] + [txtAdv10000] +
[txtAdv50000] + [txtAdv100000]) <> [txtAdvancessole] +
[txtAdvancesassetssole] + [txtAdvancesothersole] + [txtAdvancesassetspart] +
[txtAdvancesotherpart] + [txtAdvancespart] + [txtAdvancespartnp] +
[txtAdvancesassetsnp] + [txtAdvancesothernp] Then
If MsgBox(" The total of advances on Page 3 does not equal the total of
advances on Page 2" & vbCrLf & "It should be " & [txtAdv0] + [txtAdv500] +
[txtAdv1000] + [txtAdv5000] + [txtAdv10000] + [txtAdv50000] + [txtAdv100000]
& " - Do you want to accept the error?", vbYesNo, "Calculation Error") =
vbNo Then
Cancel = True

End If
End If
End If
End If
End Sub

However when I close the form with errors I don't get the error message. can
anyone see what I am doing wrong?
 
T

Tony Williams

Douglas I've looked at that. Am I right in saying that I don't use the
Before Update of the control but put the error check in the Before update of
the page on the tabcontrol and then include Allen's code
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name

Thanks
Tony
Douglas J Steele said:
Take a look at what Allen Browne has at
http://www.allenbrowne.com/bug-01.html

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Tony Williams said:
I have a form that includes a tab control. I want to check that the total in
a control on page 3 of the tab control agrees with the total of another
control on page 2 when the form is closed. I have the following code in the
Before Update event of the total on page 3
Private Sub txtAdvTot_BeforeUpdate(Cancel As Integer)
If ([txtAdv0] + [txtAdv500] + [txtAdv1000] + [txtAdv5000] + [txtAdv10000] +
[txtAdv50000] + [txtAdv100000]) <> [txtAdvTot] Then
If MsgBox(" Column 1 does not add up" & vbCrLf & "It should be " & [txtAdv0]
+ [txtAdv500] + [txtAdv1000] + [txtAdv5000] + [txtAdv10000] + [txtAdv50000]
+ [txtAdv100000] & " - Do you want to accept the error?", vbYesNo,
"Calculation Error") = vbNo Then
Cancel = True

If ([txtAdv0] + [txtAdv500] + [txtAdv1000] + [txtAdv5000] + [txtAdv10000] +
[txtAdv50000] + [txtAdv100000]) <> [txtAdvancessole] +
[txtAdvancesassetssole] + [txtAdvancesothersole] +
[txtAdvancesassetspart] +
[txtAdvancesotherpart] + [txtAdvancespart] + [txtAdvancespartnp] +
[txtAdvancesassetsnp] + [txtAdvancesothernp] Then
If MsgBox(" The total of advances on Page 3 does not equal the total of
advances on Page 2" & vbCrLf & "It should be " & [txtAdv0] + [txtAdv500]
+
[txtAdv1000] + [txtAdv5000] + [txtAdv10000] + [txtAdv50000] + [txtAdv100000]
& " - Do you want to accept the error?", vbYesNo, "Calculation Error") =
vbNo Then
Cancel = True

End If
End If
End If
End If
End Sub

However when I close the form with errors I don't get the error message. can
anyone see what I am doing wrong?
 
D

Douglas J. Steele

I'd put that code in the form's Unload event.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Tony Williams said:
Douglas I've looked at that. Am I right in saying that I don't use the
Before Update of the control but put the error check in the Before update
of the page on the tabcontrol and then include Allen's code
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name

Thanks
Tony
Douglas J Steele said:
Take a look at what Allen Browne has at
http://www.allenbrowne.com/bug-01.html

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Tony Williams said:
I have a form that includes a tab control. I want to check that the
total in
a control on page 3 of the tab control agrees with the total of another
control on page 2 when the form is closed. I have the following code in the
Before Update event of the total on page 3
Private Sub txtAdvTot_BeforeUpdate(Cancel As Integer)
If ([txtAdv0] + [txtAdv500] + [txtAdv1000] + [txtAdv5000] +
[txtAdv10000] +
[txtAdv50000] + [txtAdv100000]) <> [txtAdvTot] Then
If MsgBox(" Column 1 does not add up" & vbCrLf & "It should be " & [txtAdv0]
+ [txtAdv500] + [txtAdv1000] + [txtAdv5000] + [txtAdv10000] + [txtAdv50000]
+ [txtAdv100000] & " - Do you want to accept the error?", vbYesNo,
"Calculation Error") = vbNo Then
Cancel = True

If ([txtAdv0] + [txtAdv500] + [txtAdv1000] + [txtAdv5000] +
[txtAdv10000] +
[txtAdv50000] + [txtAdv100000]) <> [txtAdvancessole] +
[txtAdvancesassetssole] + [txtAdvancesothersole] +
[txtAdvancesassetspart] +
[txtAdvancesotherpart] + [txtAdvancespart] + [txtAdvancespartnp] +
[txtAdvancesassetsnp] + [txtAdvancesothernp] Then
If MsgBox(" The total of advances on Page 3 does not equal the total of
advances on Page 2" & vbCrLf & "It should be " & [txtAdv0] + [txtAdv500]
+
[txtAdv1000] + [txtAdv5000] + [txtAdv10000] + [txtAdv50000] + [txtAdv100000]
& " - Do you want to accept the error?", vbYesNo, "Calculation Error")
=
vbNo Then
Cancel = True

End If
End If
End If
End If
End Sub

However when I close the form with errors I don't get the error message. can
anyone see what I am doing wrong?
 
T

Tony Williams

Thanks Douglas
Tony
Douglas J. Steele said:
I'd put that code in the form's Unload event.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Tony Williams said:
Douglas I've looked at that. Am I right in saying that I don't use the
Before Update of the control but put the error check in the Before update
of the page on the tabcontrol and then include Allen's code
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name

Thanks
Tony
Douglas J Steele said:
Take a look at what Allen Browne has at
http://www.allenbrowne.com/bug-01.html

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a form that includes a tab control. I want to check that the
total
in
a control on page 3 of the tab control agrees with the total of another
control on page 2 when the form is closed. I have the following code in
the
Before Update event of the total on page 3
Private Sub txtAdvTot_BeforeUpdate(Cancel As Integer)
If ([txtAdv0] + [txtAdv500] + [txtAdv1000] + [txtAdv5000] +
[txtAdv10000]
+
[txtAdv50000] + [txtAdv100000]) <> [txtAdvTot] Then
If MsgBox(" Column 1 does not add up" & vbCrLf & "It should be " &
[txtAdv0]
+ [txtAdv500] + [txtAdv1000] + [txtAdv5000] + [txtAdv10000] +
[txtAdv50000]
+ [txtAdv100000] & " - Do you want to accept the error?", vbYesNo,
"Calculation Error") = vbNo Then
Cancel = True

If ([txtAdv0] + [txtAdv500] + [txtAdv1000] + [txtAdv5000] +
[txtAdv10000]
+
[txtAdv50000] + [txtAdv100000]) <> [txtAdvancessole] +
[txtAdvancesassetssole] + [txtAdvancesothersole] +
[txtAdvancesassetspart]
+
[txtAdvancesotherpart] + [txtAdvancespart] + [txtAdvancespartnp] +
[txtAdvancesassetsnp] + [txtAdvancesothernp] Then
If MsgBox(" The total of advances on Page 3 does not equal the total of
advances on Page 2" & vbCrLf & "It should be " & [txtAdv0] +
[txtAdv500] +
[txtAdv1000] + [txtAdv5000] + [txtAdv10000] + [txtAdv50000] +
[txtAdv100000]
& " - Do you want to accept the error?", vbYesNo, "Calculation Error")
=
vbNo Then
Cancel = True

End If
End If
End If
End If
End Sub

However when I close the form with errors I don't get the error
message.
can
anyone see what I am doing wrong?
 

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