如果在值清單中找到
expr
,
In
運算子會傳回
True
;否則,它會傳回
False
。 可以包含
Not
邏輯運算子來計算相反的情況 (也就是,不論
expr
是否不在值清單中)。
例如,可以使用
In
來決定運送到一段特定區域的訂單:
SELECT *
FROM Orders
WHERE ShipRegion In ('Avon','Glos','Som')
您也可以使用 In 來參考存在於外部資料庫檔案中的資料表或查詢:
SELECT qryValues
FROM qryValues In 'c:\files\MyDB.accdb'
下列範例會使用 Northwind.mdb 資料庫中的 [Orders] 資料表來建立一項查詢,而這項查詢會包含出貨至 Lancashire 和 Essex 的所有訂單以及出貨日期。
本範例會呼叫 EnumFields 程序,您可以在 SELECT 陳述式範例中找到該程序。
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
存取開發人員論壇
在 support.office.com 上存取說明
在 answers.microsoft.com 上存取說明
存取 UtterAccess 上的論壇
存取開發人員和 VBA 程式設計說明中心 (FMS)
存取 StackOverflow 上的文章
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。