README.md

December 5, 2022 ยท View on GitHub

IsNullEx

Description

This code provides an IsNull function like that used in SQL Server. This allows you to check if a variable contains null, and if so return a specific value. This can prevent you from having to write things like iif(not isnull(rst!FieldName), rst!FieldName, ""). For new programmers, especially those working with databases, you will quickly become aware that trying to access a database field that contains a null value often results in the dreaded error #94 - Invalid Use of Null, which means you constantly have to write code to trap for that possibility.

More Info

ValueToCheck = a variant representing he value to check for null

varWhatToReturnIfNull = the value to return if ValueToCheck is null

If ValueToCheck is null, then varWhatToReturnIfNull is returned, otherwise, ValueToCheck is returned

Submitted On
ByJared Scarbrough
LevelIntermediate
User Rating4.3 (47 globes from 11 users)
CompatibilityVB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script, ASP (Active Server Pages)
CategoryString Manipulation
WorldVisual Basic
Archive File

Source Code

Public Function IsNullEx(ValueToCheck As Variant, varWhatToReturnIfNull) As Variant
  If IsNull(ValueToCheck) Then
    IsNullEx = varWhatToReturnIfNull
  Else
    IsNullEx = ValueToCheck
  End If
End Function
Usage example:
txtClientName = IsNullEx(rst!ClientName, "unknown")