Freigeben über


Wenn...Dann...Sonst-Makroblock

Gilt für: Access 2013, Office 2013

Mit dem If-Makroblock können Sie eine Gruppe von Aktionen je nach Wert eines als Bedingung verwendeten Ausdrucks ausführen.

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

Einstellung

Für If und für Else If sind jeweils die folgenden Argumente erforderlich.

Aktionsargument

Beschreibung

Ausdruck

Die Bedingung, die Sie testen möchten. Dies muss ein Ausdruck sein, der als "Wahr" oder "Falsch" ausgewertet wird.

Bemerkungen

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.

To evaluate a different expression when the first expression is false, you can click Add Else If to insert an optional Else If block. You must enter an expression that evaluates to True or False. In this case, the block executes only if the expression is True and the first expression is False.

You can add as many Else If blocks as you like to an If block.

Sie können auf Add Else klicken, um einen optionalen Else -Block hinzuzufügen. In diesem Fall bilden die unter Else eingegebenen Aktionen den Else -Block, der nur ausgeführt wird, wenn die darüber angegebenen Aktionen nicht ausgeführt werden. Einem If -Block können Sie nur einen Else -Block hinzufügen.

Im folgenden Codebeispiel werden die Makroaktionen im ersten Block ausgeführt, wenn der Wert von [Status] größer als 0 ist. Wenn der Wert von [Status] nicht größer als 0 ist, wird der Ausdruck nach Else If ausgewertet. Die Makroaktionen im Else If -Block werden ausgeführt, wenn der Wert von [Status] gleich 0 ist. Wenn letztlich weder der erste noch der zweite Block ausgeführt wird, werden die Aktionen im Else -Block ausgeführt.

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

Sie können If-Blöcke schachteln. Das Schachteln eines If-Blocks in einem If-Block sollten Sie erwägen, um einen zweiten Ausdruck auszuwerten, wenn der erste Ausdruck "Wahr" ist. Im folgenden Codebeispiel wird der innere If-Block nur ausgeführt, wenn der Wert von [Status] sowohl größer als 0 als auch größer als 100 ist.

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