Please help with IF statement problem

R

roger

Hi All,
New to the group. Having difficulty with Greater AND Less than.

This is my code and I am trying to get greater than 100 AND less than 200 to
work.

<% if (Recordset1_total) > "100" AND (Recordset1_total) < "200" then %><img
src="images/silver.jpg"><% end if %>


Any ideas??

Many thanks!
 
W

Wayne Morgan

You're coding appears to be for a web page, is this for an Access Database.
Either way, I would guess that your problem is that you've made the numbers
into strings by putting quotes around them. Is the field a numeric or text
field? If it is a text field, you will get a text sort instead of a numeric
sort.

Example text sort:
1
11
123
2
20

As you can see, what is considered to be less than or greater than changes
if your are referring to text values instead of numeric values.
 
R

roger

Think I'm in the wrong newsgroup.
This seems to be Access.
I'm after a good ASP group. Any ides?

Thanks Anyway
 
J

John Vinson

Hi All,
New to the group. Having difficulty with Greater AND Less than.

This is my code and I am trying to get greater than 100 AND less than 200 to
work.

<% if (Recordset1_total) > "100" AND (Recordset1_total) < "200" then %><img
src="images/silver.jpg"><% end if %>

You're using the word "and" as if it were an English language
conjunction; it's not - it's a Boolean logic operator.

The AND operator takes two arguments: one to its left, the other to
its right. It evaluates each argument. If both arguments are TRUE the
result of the operator is TRUE; if either or both are false, the
result is FALSE.

In your case, it's checking the value of Recordset1.Total; if it is a
text string alphabetically greater than the text string 100, then the
left hand argument is TRUE. It then compares it to the text string 200
and returns either True or False.

It would appear that you are doing this in VBScript or some language
other than Microsoft Access VBA or Microsoft Access SQL - is that
correct? If so, you might want to post to a newsgroup appropriate for
your programming language. If Recordset1_Total is a numeric field then
you may want to just remove the quotemarks (but I'm no VBScript
expert!)

John W. Vinson[MVP]
 
W

Wayne Morgan

There are several ASP groups on this server. Check the listing of groups.
How you do this depends on how you are accessing this group.
 
Top