By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,640 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,640 IT Pros & Developers. It's quick & easy.

using if to check for multiple values

P: n/a
Hi All,
In access97 is there a way to check for multiple values in an if
statement like this

If Me!bxDistriCde <> "m" Or 1 Or 2 Or 3 Or 4 Or 5 Or 6 Or 7 Or 8 Then
or something like this
If Me!bxDistriCde <> ("m", 1, 2, 3, 4, 5, 6, 7, 8) Then

or do I have to do it like this

If Me!bxDistriCde <> "m" Or me!bxDistriCde <> 1 Or me!bxDistriCde <> 2
etc...........
thanks
bobh.

Mar 14 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
bobh wrote:
Hi All,
In access97 is there a way to check for multiple values in an if
statement like this

If Me!bxDistriCde <> "m" Or 1 Or 2 Or 3 Or 4 Or 5 Or 6 Or 7 Or 8 Then
or something like this
If Me!bxDistriCde <> ("m", 1, 2, 3, 4, 5, 6, 7, 8) Then

or do I have to do it like this

If Me!bxDistriCde <> "m" Or me!bxDistriCde <> 1 Or me!bxDistriCde <> 2
etc...........
thanks
bobh.

If Instr("M12345678",Me!bxDistriCde) Then
Mar 14 '06 #2

P: n/a
Hello, I don't think you can do it in an IF statement, but you can in a
SELECT CASE statement.

By the way, if you combine <> conditions, you probably want AND not OR:
If Me!bxDistriCde <> "m" AND me!bxDistriCde <> 1 AND me!bxDistriCde <>
2

Mar 14 '06 #3

P: n/a
You could play with this to make it do what you want, maybe.

Option Compare Binary

Sub AirCode(ByVal v As Variant)
Select Case v
Case 10 To 20
MsgBox "Between Ten and Twenty"
Case "a" To "z"
MsgBox "Lower Case"
Case DateSerial(1937, 12, 18) To DateSerial(1947, 12, 18)
MsgBox "Hmmmmm!"
Case Else
MsgBox "I dunno!"
End Select
End Sub

Sub test()
AirCode DateAdd("yyyy", -65, Date)
End Sub

Mar 14 '06 #4

P: n/a
Thanks All for your ideas on this and both these vba sets of code work

If InStr("M12345678", Me!bxDistriCde) Then
do whatever...........
End If

Select Case Me!bxDistriCde
Case "1", "2", "3", "4", "6", "7", "8", "m"
do whatever.................
End Select

thanks again
bobh.

Mar 14 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.