Microsoft Access 2010 Bible

(Rick Simeone) #1

Part II: Programming Microsoft Access


402


FIGURE 10.18

The VBA code decides whether to display the Customer page of a tab control.


The Else statement is optional. Use Else to perform an alternative set of actions when the If
condition is False:

If Condition Then
[Action to perform when Condition is True]
Else
[Action to perform when Condition is False]
End If

The Then and Else clauses can contain virtually any valid VBA statements, including another
If... Then... Else...End If:

If Condition1 Then
[Action to perform when Condition1 is True]
Else
If Condition2 Then
[Action to perform when Condition2 is True]
Else
[Action to perform when Condition2 is False]
End If
End If

Needless to say, nested If... Then... Else...End If constructs can become quite compli-
cated and confusing. The ElseIf clause sometimes helps reduce this confusion:

If Condition1 Then
[Action to perform when Condition1 is True]
ElseIf Condition2 Then
[Action to perform when Condition2 is True]
Else
[Action to perform when Condition2 is False]
End If

In this example, notice that there is only one End If statement at the bottom of the construct.
Free download pdf