using if to check for multiple values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bobh

    #1

    using if to check for multiple values

    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.

  • salad

    #2
    Re: using if to check for multiple values

    bobh wrote:[color=blue]
    > 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.
    >[/color]
    If Instr("M1234567 8",Me!bxDistriC de) Then

    Comment

    • MtnWindow@hotmail.com

      #3
      Re: using if to check for multiple values

      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

      Comment

      • Lyle Fairfield

        #4
        Re: using if to check for multiple values

        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

        Comment

        • bobh

          #5
          Re: using if to check for multiple values

          Thanks All for your ideas on this and both these vba sets of code work

          If InStr("M1234567 8", 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.

          Comment

          Working...