In operator (Microsoft Access SQL)
Applies to: Access 2013 | Access 2016
Determines whether the value of an expression is equal to any of several values in a specified list.
Syntax
expr [ Not ] In ( value1, value2, … )
expr [ Not ] In ( SELECT … )
Remarks
The In operator syntax has these parts:
Part | Description |
---|---|
expr | Expression identifying the field that contains the data you want to evaluate. |
value1, value2 | Expression or list of expressions against which you want to evaluate expr. |
If expr is found in the list of values, the In operator returns True; otherwise, it returns False. You can include the Not logical operator to evaluate the opposite condition (that is, whether expr is not in the list of values).
For example, you can use In to determine which orders are shipped to a set of specified regions:
SELECT *
FROM Orders
WHERE ShipRegion In ('Avon','Glos','Som')
You can also use In to reference a table or query that exists in an external database file:
SELECT qryValues
FROM qryValues In 'c:\files\MyDB.accdb'
Example
The following example uses the Orders table in the Northwind.mdb database to create a query that includes all orders shipped to Lancashire and Essex and the dates shipped.
This example calls the EnumFields procedure, which you can find in the SELECT statement example.
Sub InX()
Dim dbs As Database, rst As Recordset
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")
' Select records from the Orders table that
' have a ShipRegion value of Lancashire or Essex.
Set rst = dbs.OpenRecordset("SELECT " _
& "CustomerID, ShippedDate FROM Orders " _
& "WHERE ShipRegion In " _
& "('Lancashire','Essex');")
' Populate the Recordset.
rst.MoveLast
' Call EnumFields to print the contents of
' the Recordset.
EnumFields rst, 12
dbs.Close
End Sub
See also
- Access for developers forum
- Access help on support.office.com
- Access help on answers.microsoft.com
- Access forums on UtterAccess
- Access developer and VBA programming help center (FMS)
- Access posts on StackOverflow
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.