Search Tools Links Login

IsNullEx


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.

Original Author: Jared Scarbrough

Inputs

ValueToCheck = a variant representing he value to check for null
varWhatToReturnIfNull = the value to return if ValueToCheck is null

Returns

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

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")

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 143 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.