Comparing calculated controls on a tab control pages

T

Tony Williams

I have a form that has a tab control with 5 pages. On Page 4 is a calculated
control (txtClientsTot) that I want to compare with a calculated control on
Page 3 (txtTotNbrClients).
I am using this code in the BeforeUpdate property of the control on Page 4

Dim totclients As Integer
Dim totnbr As Integer

totclients = ([txtClients0] + [txtClients500] + [txtClients1000] +
[txtClients5000] + [txtClients10000] + [txtClients50000] +
[txtClients100000])
totnbr = ([txtClientsdomfacsole] + [txtClientsdomidsole] +
[txtClientsexpsole] + [txtClientsimpsole] + [txtClientsdomfacpart] +
[txtClientsdomidpart] + [txtClientsexppart] + [txtClientsimppart])

If totclients <> totnbr Then
If MsgBox("Total does not agree with Total Number of Clients on Page 3" &
vbCrLf & "It should be " & [txtTotNbrClients] & " - Do you want to accept
the error?", vbYesNo, "Calculation Error") = vbNo Then
Cancel = True
End If
End If

However this doesn't work. If the incorrect total is calculated on Page 4 I
don't get any message. Can someone help please?
Thanks
Tony
 
R

Rob Oldfield

Which of totclients and totnbr is giving you a result that you're not
expecting? Whichever one it is, which of the components that you're adding
up is different from what you expect?

And if they're calculated controls, then why are you running code in the
BeforeUpdate event? If it's calculated then you shouldn't need to be
editing it.
 
T

Tony Williams

Thanks for your comments Rob
On the two pages of my tabcontrol are a group of figures which analyse the
total number of clients in different ways. The purpose of this code is to
check that the total number of clients shown on both pages is the same. Both
totals are as you can see the sum of the number of clients, one is by
turnover and the other is by type of business. I want to check that even
though the analysis is different the totals are the same. I thought that as
the total was calculated on Page 4 I could check that total with the total
on Page 3
Cheers
Tony
Rob Oldfield said:
Which of totclients and totnbr is giving you a result that you're not
expecting? Whichever one it is, which of the components that you're adding
up is different from what you expect?

And if they're calculated controls, then why are you running code in the
BeforeUpdate event? If it's calculated then you shouldn't need to be
editing it.


Tony Williams said:
I have a form that has a tab control with 5 pages. On Page 4 is a calculated
control (txtClientsTot) that I want to compare with a calculated
control
on
Page 3 (txtTotNbrClients).
I am using this code in the BeforeUpdate property of the control on Page 4

Dim totclients As Integer
Dim totnbr As Integer

totclients = ([txtClients0] + [txtClients500] + [txtClients1000] +
[txtClients5000] + [txtClients10000] + [txtClients50000] +
[txtClients100000])
totnbr = ([txtClientsdomfacsole] + [txtClientsdomidsole] +
[txtClientsexpsole] + [txtClientsimpsole] + [txtClientsdomfacpart] +
[txtClientsdomidpart] + [txtClientsexppart] + [txtClientsimppart])

If totclients <> totnbr Then
If MsgBox("Total does not agree with Total Number of Clients on Page 3" &
vbCrLf & "It should be " & [txtTotNbrClients] & " - Do you want to accept
the error?", vbYesNo, "Calculation Error") = vbNo Then
Cancel = True
End If
End If

However this doesn't work. If the incorrect total is calculated on Page
4
I
don't get any message. Can someone help please?
Thanks
Tony
 
R

Rob Oldfield

In that case you shouldn't be attempting to validate the data in the after
update of any of the individual controls. If a user goes to txtClients0 (or
any of the others) and then tries to close the form or go to another record.
You should be doing it in the before update event of the form itself.


Tony Williams said:
Thanks for your comments Rob
On the two pages of my tabcontrol are a group of figures which analyse the
total number of clients in different ways. The purpose of this code is to
check that the total number of clients shown on both pages is the same. Both
totals are as you can see the sum of the number of clients, one is by
turnover and the other is by type of business. I want to check that even
though the analysis is different the totals are the same. I thought that as
the total was calculated on Page 4 I could check that total with the total
on Page 3
Cheers
Tony
Rob Oldfield said:
Which of totclients and totnbr is giving you a result that you're not
expecting? Whichever one it is, which of the components that you're adding
up is different from what you expect?

And if they're calculated controls, then why are you running code in the
BeforeUpdate event? If it's calculated then you shouldn't need to be
editing it.


control
Page
4
Dim totclients As Integer
Dim totnbr As Integer

totclients = ([txtClients0] + [txtClients500] + [txtClients1000] +
[txtClients5000] + [txtClients10000] + [txtClients50000] +
[txtClients100000])
totnbr = ([txtClientsdomfacsole] + [txtClientsdomidsole] +
[txtClientsexpsole] + [txtClientsimpsole] + [txtClientsdomfacpart] +
[txtClientsdomidpart] + [txtClientsexppart] + [txtClientsimppart])

If totclients <> totnbr Then
If MsgBox("Total does not agree with Total Number of Clients on Page
3"
&
vbCrLf & "It should be " & [txtTotNbrClients] & " - Do you want to accept
the error?", vbYesNo, "Calculation Error") = vbNo Then
Cancel = True
End If
End If

However this doesn't work. If the incorrect total is calculated on
Page
 
T

Tony Williams

Thanks Rob I'll try that
Tony
Rob Oldfield said:
In that case you shouldn't be attempting to validate the data in the after
update of any of the individual controls. If a user goes to txtClients0 (or
any of the others) and then tries to close the form or go to another record.
You should be doing it in the before update event of the form itself.


Tony Williams said:
Thanks for your comments Rob
On the two pages of my tabcontrol are a group of figures which analyse the
total number of clients in different ways. The purpose of this code is to
check that the total number of clients shown on both pages is the same. Both
totals are as you can see the sum of the number of clients, one is by
turnover and the other is by type of business. I want to check that even
though the analysis is different the totals are the same. I thought that as
the total was calculated on Page 4 I could check that total with the total
on Page 3
Cheers
Tony
Rob Oldfield said:
Which of totclients and totnbr is giving you a result that you're not
expecting? Whichever one it is, which of the components that you're adding
up is different from what you expect?

And if they're calculated controls, then why are you running code in the
BeforeUpdate event? If it's calculated then you shouldn't need to be
editing it.


I have a form that has a tab control with 5 pages. On Page 4 is a
calculated
control (txtClientsTot) that I want to compare with a calculated control
on
Page 3 (txtTotNbrClients).
I am using this code in the BeforeUpdate property of the control on
Page
4

Dim totclients As Integer
Dim totnbr As Integer

totclients = ([txtClients0] + [txtClients500] + [txtClients1000] +
[txtClients5000] + [txtClients10000] + [txtClients50000] +
[txtClients100000])
totnbr = ([txtClientsdomfacsole] + [txtClientsdomidsole] +
[txtClientsexpsole] + [txtClientsimpsole] + [txtClientsdomfacpart] +
[txtClientsdomidpart] + [txtClientsexppart] + [txtClientsimppart])

If totclients <> totnbr Then
If MsgBox("Total does not agree with Total Number of Clients on Page
3"
&
vbCrLf & "It should be " & [txtTotNbrClients] & " - Do you want to accept
the error?", vbYesNo, "Calculation Error") = vbNo Then
Cancel = True
End If
End If

However this doesn't work. If the incorrect total is calculated on
Page
4
I
don't get any message. Can someone help please?
Thanks
Tony
 
T

Tony Williams

Rob tried in beforeUpdate of form and still didn't get any message when
totals were different? Any other ideas?I'm baffled on this one it seems such
an easy thing to do?
Thanks
Tony
Rob Oldfield said:
In that case you shouldn't be attempting to validate the data in the after
update of any of the individual controls. If a user goes to txtClients0 (or
any of the others) and then tries to close the form or go to another record.
You should be doing it in the before update event of the form itself.


Tony Williams said:
Thanks for your comments Rob
On the two pages of my tabcontrol are a group of figures which analyse the
total number of clients in different ways. The purpose of this code is to
check that the total number of clients shown on both pages is the same. Both
totals are as you can see the sum of the number of clients, one is by
turnover and the other is by type of business. I want to check that even
though the analysis is different the totals are the same. I thought that as
the total was calculated on Page 4 I could check that total with the total
on Page 3
Cheers
Tony
Rob Oldfield said:
Which of totclients and totnbr is giving you a result that you're not
expecting? Whichever one it is, which of the components that you're adding
up is different from what you expect?

And if they're calculated controls, then why are you running code in the
BeforeUpdate event? If it's calculated then you shouldn't need to be
editing it.


I have a form that has a tab control with 5 pages. On Page 4 is a
calculated
control (txtClientsTot) that I want to compare with a calculated control
on
Page 3 (txtTotNbrClients).
I am using this code in the BeforeUpdate property of the control on
Page
4

Dim totclients As Integer
Dim totnbr As Integer

totclients = ([txtClients0] + [txtClients500] + [txtClients1000] +
[txtClients5000] + [txtClients10000] + [txtClients50000] +
[txtClients100000])
totnbr = ([txtClientsdomfacsole] + [txtClientsdomidsole] +
[txtClientsexpsole] + [txtClientsimpsole] + [txtClientsdomfacpart] +
[txtClientsdomidpart] + [txtClientsexppart] + [txtClientsimppart])

If totclients <> totnbr Then
If MsgBox("Total does not agree with Total Number of Clients on Page
3"
&
vbCrLf & "It should be " & [txtTotNbrClients] & " - Do you want to accept
the error?", vbYesNo, "Calculation Error") = vbNo Then
Cancel = True
End If
End If

However this doesn't work. If the incorrect total is calculated on
Page
4
I
don't get any message. Can someone help please?
Thanks
Tony
 
T

Tony Williams

Sorry Rob, works fine - now typo in my code
Thanks again
Tony
Tony Williams said:
Thanks Rob I'll try that
Tony
Rob Oldfield said:
In that case you shouldn't be attempting to validate the data in the after
update of any of the individual controls. If a user goes to txtClients0 (or
any of the others) and then tries to close the form or go to another record.
You should be doing it in the before update event of the form itself.


Tony Williams said:
Thanks for your comments Rob
On the two pages of my tabcontrol are a group of figures which analyse the
total number of clients in different ways. The purpose of this code is to
check that the total number of clients shown on both pages is the
same.
Both
totals are as you can see the sum of the number of clients, one is by
turnover and the other is by type of business. I want to check that even
though the analysis is different the totals are the same. I thought
that
as
the total was calculated on Page 4 I could check that total with the total
on Page 3
Cheers
Tony
Which of totclients and totnbr is giving you a result that you're not
expecting? Whichever one it is, which of the components that you're
adding
up is different from what you expect?

And if they're calculated controls, then why are you running code in the
BeforeUpdate event? If it's calculated then you shouldn't need to be
editing it.


I have a form that has a tab control with 5 pages. On Page 4 is a
calculated
control (txtClientsTot) that I want to compare with a calculated
control
on
Page 3 (txtTotNbrClients).
I am using this code in the BeforeUpdate property of the control
on
Page
4

Dim totclients As Integer
Dim totnbr As Integer

totclients = ([txtClients0] + [txtClients500] + [txtClients1000] +
[txtClients5000] + [txtClients10000] + [txtClients50000] +
[txtClients100000])
totnbr = ([txtClientsdomfacsole] + [txtClientsdomidsole] +
[txtClientsexpsole] + [txtClientsimpsole] + [txtClientsdomfacpart] +
[txtClientsdomidpart] + [txtClientsexppart] + [txtClientsimppart])

If totclients <> totnbr Then
If MsgBox("Total does not agree with Total Number of Clients on
Page
3"
&
vbCrLf & "It should be " & [txtTotNbrClients] & " - Do you want to
accept
the error?", vbYesNo, "Calculation Error") = vbNo Then
Cancel = True
End If
End If

However this doesn't work. If the incorrect total is calculated on Page
4
I
don't get any message. Can someone help please?
Thanks
Tony
 

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