locked
Use IN within VBA If statement RRS feed

  • Question

  • Hello,

    Is it possible to use the IN condition within a VBA If statement in Access 2013.

    I've tried.

    If [Forms]![frmAg1]![tboBOID] In (1270, 2037, 2098, 3600, 3610, 3765, 3823) Then
    Me.cmdFlghtInfo.Visible = True
    Else
    Me.cmdFlghtInfo.Visible = False
    End If

    But I get Compile error:

    Expected: Then or GoTo


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.

    Tuesday, August 4, 2015 12:11 PM

Answers

  • Hi, I don't think so. Instead, try using a Select Case statement. For example:

    Select Case Forms!frmAg1.tboBOID

    Case 1270, 2037, 2098, etc...

    'do your stuff

    Case Else

    'do other stuff

    End Select

    Hope that helps. ..

    • Marked as answer by DriveEV Tuesday, August 4, 2015 1:03 PM
    Tuesday, August 4, 2015 12:28 PM
  • If [Forms]![frmAg1]![tboBOID] In (1270, 2037, 2098, 3600, 3610, 3765, 3823) Then

    Hi h2fcell,

    The IN component is for SQL-expressions.

    In VBA you could use:

    Select Case [Forms]![frmAg1]![tboBOID]
    Case 1270, 2037, 2098, 3600, 3610, 3765, 3823
      Me.cmdFlghtInfo.Visible = True
    Case Else
      Me.cmdFlghtInfo.Visible = False
    End Select
    

    Imb.

    • Proposed as answer by Dziubek Michał Tuesday, August 4, 2015 12:35 PM
    • Marked as answer by DriveEV Tuesday, August 4, 2015 1:03 PM
    Tuesday, August 4, 2015 12:29 PM

All replies

  • Hi, I don't think so. Instead, try using a Select Case statement. For example:

    Select Case Forms!frmAg1.tboBOID

    Case 1270, 2037, 2098, etc...

    'do your stuff

    Case Else

    'do other stuff

    End Select

    Hope that helps. ..

    • Marked as answer by DriveEV Tuesday, August 4, 2015 1:03 PM
    Tuesday, August 4, 2015 12:28 PM
  • If [Forms]![frmAg1]![tboBOID] In (1270, 2037, 2098, 3600, 3610, 3765, 3823) Then

    Hi h2fcell,

    The IN component is for SQL-expressions.

    In VBA you could use:

    Select Case [Forms]![frmAg1]![tboBOID]
    Case 1270, 2037, 2098, 3600, 3610, 3765, 3823
      Me.cmdFlghtInfo.Visible = True
    Case Else
      Me.cmdFlghtInfo.Visible = False
    End Select
    

    Imb.

    • Proposed as answer by Dziubek Michał Tuesday, August 4, 2015 12:35 PM
    • Marked as answer by DriveEV Tuesday, August 4, 2015 1:03 PM
    Tuesday, August 4, 2015 12:29 PM