A
Adam Bryce
Hi,
I came across this when coding a form in Acc2002, and found I could
replicate it, but had no idea why it happens:
I create a form with four text boxes: A, B, C and Total
A - C have a default value of zero, and an afterUpdate event that calls a
function within the form code:
If [total] <> 1 Then
[total].forecolor = 255 'highlight text (red)
Else
[total].forecolor = 0 'normal text (black)
End If
The Total Box has a control source of:
=cdbl([A])+cdbl()+cdbl([C])
all the boxes are formatted as percentage*, with no d.p. - the idea being
that if they don't sum to 100%, the user is warned by the total turning red.
*I've tried it without formatting, and it doesn't change the problem at all.
My problem is that, with certain combinations of A, B and C, the box turns
red even if the values sum to 100.
For example having A-C being 30%, 35%, 35% respectively results in '100%'
displayed in red. However, A-C entered as 35%, 35% and 30% results in '100%'
displayed in black.
Having checked the code, it turns out that in the former case, the value of
[total] is being returned as "1" instead of 1.
I've worked around this in my real code by just changing the condition to <>
"1", but I'm still perplexed as to why the order of the numbers in the
expression changes the type of the result.
Can anyone help explain this, or even better, tell me where I'm going wrong
and how to avoid it in future?
Thanks,
Adam.
I came across this when coding a form in Acc2002, and found I could
replicate it, but had no idea why it happens:
I create a form with four text boxes: A, B, C and Total
A - C have a default value of zero, and an afterUpdate event that calls a
function within the form code:
If [total] <> 1 Then
[total].forecolor = 255 'highlight text (red)
Else
[total].forecolor = 0 'normal text (black)
End If
The Total Box has a control source of:
=cdbl([A])+cdbl()+cdbl([C])
all the boxes are formatted as percentage*, with no d.p. - the idea being
that if they don't sum to 100%, the user is warned by the total turning red.
*I've tried it without formatting, and it doesn't change the problem at all.
My problem is that, with certain combinations of A, B and C, the box turns
red even if the values sum to 100.
For example having A-C being 30%, 35%, 35% respectively results in '100%'
displayed in red. However, A-C entered as 35%, 35% and 30% results in '100%'
displayed in black.
Having checked the code, it turns out that in the former case, the value of
[total] is being returned as "1" instead of 1.
I've worked around this in my real code by just changing the condition to <>
"1", but I'm still perplexed as to why the order of the numbers in the
expression changes the type of the result.
Can anyone help explain this, or even better, tell me where I'm going wrong
and how to avoid it in future?
Thanks,
Adam.