Need Help w/Nested IF Statements

markey

Registered User.
Local time
Today, 14:44
Joined
Oct 25, 2007
Messages
17
I've tried to setup a nested if statement with no results. Any help is much appreciated. Here is how it works:

If Me.txtTBASS is < 44.5, than Me.txtTBASSpts = 0
If Me.txtTBASS is >= 44.5 And <52, than Me.txtTBASSpts = 40
If Me.txtTBASS is >= 52 And <60, than Me.txtTBASSpts = 70
If Me.txtTBASS is >= 60 And <68, than Me.txtTBASSpts = 135
If Me.txtTBASS is >= 68 And <76, than Me.txtTBASSpts = 205
If Me.txtTBASS is >= 76, than Me.txtTBASSpts = 270

This example doesn't fit the syntax, but I wanted the logic to be apparent. Can someone please help out with my first nested if statement. Thanks.
 
I would start by replacing the ">=" and "<" with "between"
and also replace "Than" with "Then"

Garry
 
I would start by replacing the ">=" and "<" with "between"
and also replace "Than" with "Then"

Garry

Can you give me an example of what the code would look like, I keep getting errors. Thx.
 
Hi Markey,

Try this

Code:
If Me.txtTBASS  < 44.5 Then Me.txtTBASSpts = 0
If Me.txtTBASS >= 44.5 And Me.txtTBASS  <52 Then Me.txtTBASSpts = 40
If Me.txtTBASS  >= 52 And Me.txtTBASS  <60 Then Me.txtTBASSpts = 70
If Me.txtTBASS >= 60 And Me.txtTBASS  <68 Then Me.txtTBASSpts = 135
If Me.txtTBASS >= 68 And Me.txtTBASS  <76 Then Me.txtTBASSpts = 205
If Me.txtTBASS >= 76  Then Me.txtTBASSpts = 270

Garry
 
This looks like an evalution that would benefit from a CASE statement rather than a series of IF statements.

Code:
SELECT CASE me.txtTbass
  CASE is < 44.5
    me.txtTBASSpts = 0
 CASE is < 52
    me.txtTBASSpts = 40
 CASE is < 60
   me.txtTBASSpts = 70
 CASE is < 68
  me.txtTBASSpts = 135
 CASE is < 76
  me.txtTBASSpts = 205
 CASE is > 76
  me.txtTBASSpts = 270
END SELECT

That's about as simple as I can make it, in this example you do need to keep your case statements in order, but you could use:

Code:
CASE 44.5 to 51 
 me.txtTBASSpts = 40

to be more explicit in how you're evaluting your response.

CASE ELSE

Is a handy catchall for anything that doesn't fit your standard responses.
 
Code:
Select Case Me!txtTbass
  Case Is < 44.5
    strTBASSpts = 0
 Case Is < 52
    strTBASSpts = 40
 Case Is < 60
    strTBASSpts = 70
 Case Is < 68
    strTBASSpts = 135
 Case Is < 76
    strTBASSpts = 205
 Case Is > 76
    strTBASSpts = 270
End Select

Me!txtTBASSpts.Value = strTBASSpts

If you got option explicit on then Dim strTBASSpts as String
 
Markey,

Are you trying to accomplish the same thing that you already accomplished here??

Or is this just a repeat of that thread?? Figured I'd ask (if you're "listening"), since this thread has once again risen from the ashes. :)
 

Users who are viewing this thread

Back
Top Bottom