VBA/Excel/Access/Word/Data Type Functions/IsNull

Материал из VB Эксперт
Перейти к: навигация, поиск

If...Then...Else and IsNull

Sub cmdIfThenElse()
 Dim txtName As String
 Dim txtAge As String
 If IsNull(txtName) Or IsNull(txtAge) Then
    msgBox "Name or Age is Blank"
    msgBox "Your Name Is " & txtName & " And Your Age Is " & txtAge
  End If
End Sub

Loop through all of the records in the recordset for non-null value

Sub LoopProjects()
    Dim rst As ADODB.Recordset
    Set rst = New ADODB.Recordset
    rst.Open "Employees", CurrentProject.Connection
    Do Until rst.EOF
        Debug.Print rst!Title, rst!City
        If IsNull(rst!Region) Then
            Debug.Print "No Value!!"
        End If
End Sub

Working with Null

Sub NullVar()
    Dim vntName As Variant
    Debug.Print IsEmpty(vntName) "Prints True
    Debug.Print IsNull(vntName) "Prints False
    vntName = Null
    Debug.Print IsNull(vntName) "Prints True
End Sub