Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

您可以使用 Access 桌面資料庫和 Access Web App 中的 If 宏區 塊,根據表示式的值來條件化執行一組宏指令。

          If 
          expression 
          Then 
 Insert macro actions here ... 
Else If expression 
 Insert macro actions here ... 
Else 
 Insert macro actions here ... 
End If

Access 中的 IfThenElse 巨集區塊

設定

對於 If Else If,需要下列自變數。

巨集指令引數

描述

Expression

這是您想要測試的條件。 它必須是評估為 True 或 False 的運算式。

註解

當您選取 [如果 宏區塊],文本框隨即出現,讓您可以輸入代表您要測試之條件的表達式。 此外,下拉式方塊會出現,您可以在其中插入宏指令,而下方則會自動顯示 “End If” 文字。 If 和 End If 括號可在其中輸入動作群組或區塊的區域。 只有當您輸入的表示式為 True 時,封鎖才會執行。

若要在第一個運算式為 False 時評估不同的運算式,您可以按兩下 [新增 Else If ] 以插入選用的 Else If 區塊。 您必須輸入評估為 True 或 False 的運算式。 在此情況下,只有在表達式為 True 且第一個表達式為 False 時,區塊才會執行。

您可以視需要新增任意數量 的 Else If 區塊至 If 區塊。

您可以按下 [新增其他 專案] 來插入選用的 Else 區塊。 在此情況下,您在 Else 區塊下方插入的動作會形成 Else 區塊,只有在上述動作沒有執行時才會執行。 您可以新增單一 Else 區塊至 If 區塊。

在下列程式代碼範例中,如果 [狀態] 的值大於0,則會執行第一個區塊中的宏指令。 如果 [狀態] 的值不大於 0,則評估 Else If 之後的運算式。 如果 [狀態] 的值等於 0,則 Else If 區塊中的宏指令會執行。 最後,如果既不執行第一個區塊或第二個區塊, 則會執行 Else 區塊中的動作。

            If 
            [Status] > 0 
            Then 
 Insert macro actions here ... 
Else If [Status] = 0 
 Insert macro actions here ... 
Else 
 Insert macro actions here ... 
End If

您可以巢狀 If 區塊。 如果您想要 在第一個 表達式為 True 時評估第二個運算式,請考慮在 If 區塊 內巢狀嵌入 If 區塊。 在下列程式代碼範例中,內部 If 區塊只會在 [狀態] 的值同時大於 0 大於 100 時執行。

            If 
            [Status] > 0 
            Then 
 Insert macro actions here ... 
 If [Status] > 100 
 Insert macro actions here ... 
 EndifEnd If

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×