VBA/Excel/Access/Word/Data Type Functions/IsNull
If...Then...Else and IsNull
<source lang="vb">
Sub cmdIfThenElse()
Dim txtName As String Dim txtAge As String If IsNull(txtName) Or IsNull(txtAge) Then msgBox "Name or Age is Blank" Else msgBox "Your Name Is " & txtName & " And Your Age Is " & txtAge End If
End Sub
</source>
Loop through all of the records in the recordset for non-null value
<source lang="vb">
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 rst.MoveNext Loop
End Sub
</source>
Working with Null
<source lang="vb">
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
</source>