And Operator

See Also              Example

Used to perform a logical conjunction on two expressions.

Syntax

result = expr1 And expr2

Remarks

If, and only if, both expressions evaluate True, result is True.  If either expression evaluates False, result is False.  The following table illustrates how result is determined:

If expr1         And expr2       The result
is                  is                     is

True              True                True

True              False               False

True              Null                 Null

False             True                False

False             False               False

False             Null                 False

Null               True                Null

Null               False               False

Null               Null                 Null

The And operator also performs a bit-wise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following truth table:

If bit in          And bit in         The result
expr1 is         expr2 is            is

0                   0                       0

0                   1                       0

1                   0                       0

1                   1                       1

See Also

Arithmetic Operators

Comparison Operators

Concatenation Operators

Logical Operators

Operator Precedence

Other Operators

And Operator Example

The example displays a message that depends on the value of variables A, B, and C, assuming that no variable is a Null.  If A = 10, B = 8, and C = 6, both expressions evaluate True.  Because both expressions are True, the And expression is also True.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

Sub Form_Click ()

Dim A, B, C, Msg                      ' Declare variables.

A = 10: B = 8: C = 6                  ' Assign values.

If A > B And B > C Then               ' Evaluate expressions.

Msg = "Both expressions are True."

Else

Msg = "One or both expressions are False."

End If

MsgBox Msg                            ' Display results.

End Sub