More IIf Problems

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Your statement < 31 AND > 41 is not between but outside.

Between would be >=31 AND <=41 for all inclusive of 31 through 41.
 
How do you do between numbers in an if statement?

If Me.TxtItemID < 31 AND > 41 Then
DoCmd.OpenForm "frmMsgSelect"
Forms!frmMsgSelect!TxtMsg = "DISCOUNTS ONLY"
Else:
End If


This syntax doesn't seem to be right.
Thanks
DS
 
How do you do between numbers in an if statement?

If Me.TxtItemID < 31 AND > 41 Then
DoCmd.OpenForm "frmMsgSelect"
Forms!frmMsgSelect!TxtMsg = "DISCOUNTS ONLY"
Else:
End If


This syntax doesn't seem to be right.
Thanks
DS

It isn't. A comparison operator is NOT an English language conjunction - it
just looks like one!

The correct syntax is

If Me.txtItemID > 31 AND Me.txtItemID < 41 Then

Note that you had the greaterthan and lessthan operators reversed: even if you
had repeated Me.txtItemID, this would have opened the form only for txtItemID
values which are simultaneously less than 31 and also greater than 41. Of
course that can never happen! My suggested change will open the form for item
ID's 32, 33, 34, ..., 40, but not for 31 or less or for 41 or more.

John W. Vinson [MVP]
 
John said:
It isn't. A comparison operator is NOT an English language conjunction - it
just looks like one!

The correct syntax is

If Me.txtItemID > 31 AND Me.txtItemID < 41 Then

Note that you had the greaterthan and lessthan operators reversed: even if you
had repeated Me.txtItemID, this would have opened the form only for txtItemID
values which are simultaneously less than 31 and also greater than 41. Of
course that can never happen! My suggested change will open the form for item
ID's 32, 33, 34, ..., 40, but not for 31 or less or for 41 or more.

John W. Vinson [MVP]
Thanks, John.
Only one thing I do want the form to open if it's Less than 31 or
greater than 41. I'll give it a try. Thank you once again John
DS
 
Only one thing I do want the form to open if it's Less than 31 or
greater than 41. I'll give it a try. Thank you once again John

Then use the operator OR instead of the operator AND.

John W. Vinson [MVP]
 
Back
Top