次の方法で共有


If...Then...Else マクロ ブロック

適用先: Access 2013、Office 2013

式の値に応じた条件に基づいてアクションのグループを実行するには、If マクロ ブロックを使用します。

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

設定

If および Else If の両方に次の引数が必要です。

アクションの引数

説明

Expression

テストする条件です。 真または偽のいずれかに評価できる式でなければなりません。

注釈

When you select the If macro block, a textbox appears so that you can enter an expression that represents the condition you wish to test. In addition, a combo box appears where you can insert a macro action, below which the text "End If" automatically displays. The If and the End If bracket an area in which you can enter a group, or block, of actions. The block executes only if the expression that you enter is True.

1 つ目の式が False だった場合に別の式を評価するには、 Add Else If をクリックし、オプションの Else If ブロックを挿入します。 True または False として評価される式を入力する必要があります。 1 つ目の式が False で、この式が True の場合のみ、ブロックが実行されます。

If ブロックには、任意の数の Else If ブロックを追加できます。

You can click Add Else to insert an optional Else block. In this case, the actions that you insert below the Else form the Else block, which executes only when the actions above do not. You can add a single Else block to an If block.

次のコード例では、1 つ目のブロックのマクロ アクションは、[Status] の値が 0 より大きい場合に実行されます。 [Status] の値が 0 より大きくない場合は、 Else If に続く式が評価されます。 Else If ブロックのマクロ アクションは、[Status] の値が 0 の場合に実行されます。 最後に、1 つ目のブロックも 2 つ目のブロックも実行されない場合、 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 ブロックは、入れ子にすることができます。 最初の式が真であった場合に 2番目の式を評価させたい場合は、If ブロック内に If ブロックを入れ子にします。 次のコード例では、内側の If ブロックは、[Status] の値が 0 より大きく、かつ 100 より大きい場合にのみ実行されます。

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