View Full Version : If Statement using les than and more than


jojo86
12-21-2007, 03:06 AM
Hi

I have a field that needs to be populated with percentages according to the site area given, which is this:
SITE_AREA GN_Ratio
Less than 0.4 100%
Between 0.4 and 2 90%
Between 2 and 10 75%
More than 10 50%

I am attempting to try and populate a field on one of my forms using the following code, but it doesn't seem to be working:
If SITE_AREA <= "0.4" Then
GN_Ratio = "100.00%"
Else
If SITE_AREA >"0.4" < "2" Then
GN_Ratio = "90.00%"
Else
If SITE_AREA >="2" < "10" Then
GN_Ratio = "75.00%"
Else
GN_Ratio = "50.00%"
End If
End If
End If

I have put this code in the On Load event and the On Current event of the form. Just to mention, this form (Yield) is a subform in the main form (Primary).

I need to get this finished before the end of play today due to christmas so any help would be much appreciated! Thanks

ted.martin
12-21-2007, 03:27 AM
You need to use AND
so:
If SITE_AREA >"0.4" AND < "2" Then


I would also suggest you use SELECT CASE rather than all the IF's

jojo86
12-21-2007, 03:33 AM
You need to use AND
so:
If SITE_AREA >"0.4" AND < "2" Then


I would also suggest you use SELECT CASE rather than all the IF's
I have just tried to put in the AND bit and it now says "Compile Error: Expected: expression" and the < is highlighted. Don't know what you mean by SELECT CASE either.

Rabbie
12-21-2007, 04:07 AM
I have just tried to put in the AND bit and it now says "Compile Error: Expected: expression" and the < is highlighted. Don't know what you mean by SELECT CASE either.

Try

If SITE_AREA >"0.4" AND SITE_AREA< "2" Then


IF SITE_AREA is defined as a number then try


If SITE_AREA > 0.4 AND SITE_AREA < 2 Then


See Access help for more info on CASE

ted.martin
12-21-2007, 04:17 AM
Try this
Select Case SITE_AREA

Case Is <= 0.4
GN_Ratio = "100.00&#37;"

Case 0.4 To 2
GN_Ratio = "90.00%"

Case 2 To 10
GN_Ratio = "75.00%"

Case Else
GN_Ratio = "50.00%"

End Select