Comparing calculated controls on a tab control pages

Comparing calculated controls on a tab control pages

Post by Tony Willi » Fri, 18 Mar 2005 19:47:06


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
 
 
 

Comparing calculated controls on a tab control pages

Post by Rob Oldfie » Sat, 19 Mar 2005 06:04:12

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.




calculated
on
I

 
 
 

Comparing calculated controls on a tab control pages

Post by Tony Willi » Sat, 19 Mar 2005 16:15:01

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


adding


control
4
&
accept
4
 
 
 

Comparing calculated controls on a tab control pages

Post by Rob Oldfie » Sat, 19 Mar 2005 16:47:06

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.




Both
as




Page
3"
Page
 
 
 

Comparing calculated controls on a tab control pages

Post by Tony Willi » Sat, 19 Mar 2005 17:20:23

hanks Rob I'll try that
Tony
"Rob Oldfield" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
(or
record.
the
to
total
the


 
 
 

Comparing calculated controls on a tab control pages

Post by Tony Willi » Sat, 19 Mar 2005 17:25:03

ob 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" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
(or
record.
the
to
total
the


 
 
 

Comparing calculated controls on a tab control pages

Post by Tony Willi » Sat, 19 Mar 2005 17:29:09

orry Rob, works fine - now typo in my code
Thanks again
Tony
"Tony Williams" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
after
same.
even
that
not
be
on
+
Page