If

If-Then-Else, VBA statement.

Syntax
      If condition_1 Then
         result_1
    [ ElseIf condition_2 Then
           result_2 ]
      ...
    [ ElseIf condition_n Then
           result_n ]
      End If

Key
   condition_n      Conditions are evaluated in the order listed.
                    Once a condition is found to be true, the corresponding code
                    will be executed and no further conditions will be evaluated.

   result_n         The code to be executed when a condition is met.

Comparison operators:

Less than <, Less than or equal to <=
Greater than >, Greater than or equal to >=
Not equal <>, Equal =

By default comparisons are case sensitive, to make them case insensitive, use UCase() or LCase()
If ucase(string1) = ucase(string2) then...

Examples

Dim intVoltage as Integer
Dim strDescription as String

intVoltage = Me!txtVoltage

 If intVoltage = 110 Then
   strDescription = "US voltage"
 ElseIF intVoltage > 200
   strDescription = "European voltage"
 Else
   strDescription = "Other voltage"
 End If

MsgBox strDescription

“You see things; and you say 'Why?' But I dream things that never were; and I say 'why not?'” ~ George Bernard Shaw

Related

Nz - Detect a NULL value or Zero Length string.
IIf - If-Then-Else function (SQL)
Case - If Then Else
For - Loop.


 
Copyright © 1999-2024 SS64.com
Some rights reserved