IF statement problem

G

Guest

I have some code which checks to see if the total percentage amounts of a
formula's ingredients equal 100% (or 1). The values in the percent field are
data type double and are entered as decimals (.2 or .95, etc). Here's an
example of the code...

Public Function CheckPercent(lngID as Long) as Boolean
....
If rs!SumOfIngredientPercent = 1 Then
CheckPercent = True
Else
CheckPercent = False
End If
....
End Function

On some of the records, the code returns False even though the statement
should return True. I have stepped thru the code numerous times on the
records where it should return true. The value = 1 but the code just
continues to the Else statement. Any suggestions on why this could be
happening? I have tried changing the statement to "If
rs!SumOfIngredientPercent >=1" just in case, but the same thing occurs.
Again, what's weird is that most of the times it returns the correct result.
For example, records 1-13 return accurately and then record 14 doesn't.

TIA
Diana
 
G

Guest

Hi Diana,

Just a simple thing check for null in your statement. I have had problems
with SQL back end where you set up default as 0 and puts null not zero.

You could try to get the answer first to see what they add up to. This
might reveal the problem?

If this does not answer your problem perhaps someone else might know. Worth
a try anyway.

Trev
 
K

Keith Wilby

Diana Criscione said:
On some of the records, the code returns False even though the statement
should return True. I have stepped thru the code numerous times on the
records where it should return true. The value = 1 but the code just
continues to the Else statement. Any suggestions on why this could be
happening? I have tried changing the statement to "If
rs!SumOfIngredientPercent >=1" just in case, but the same thing occurs.
Again, what's weird is that most of the times it returns the correct
result.
For example, records 1-13 return accurately and then record 14 doesn't.

I'm only responding with this because no-one else has but I believe it's an
issue with the way Access processes numbers ... decimals and roundings. I
don't know specifically, I just remember reading it somewhere, so it might
be worth trying the CInt function:

If CInt(rs!SumOfIngredientPercent) = 1 Then
CheckPercent = True
Else
CheckPercent = False
End If

Regards,
Keith.
www.keithwilby.com
 
G

Guest

Thanks! I will give that a try. It is just so strange that it works most of
the time.
 

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