VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



IsNullEx

by Jared Scarbrough (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (11 Votes)

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.

Inputs
ValueToCheck = a variant representing he value to check for null varWhatToReturnIfNull = the value to return if ValueToCheck is null
Code Returns
If ValueToCheck is null, then varWhatToReturnIfNull is returned, otherwise, ValueToCheck is returned

Rate IsNullEx

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

Download this snippet    Add to My Saved Code

IsNullEx Comments

No comments have been posted about IsNullEx. Why not be the first to post a comment about IsNullEx.

Post your comment

Subject:
Message:
0/1000 characters