Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IsNothing Function since I always forget it is not part of VBA IsSomething functions

Office / VBA General

IsNothing Function since I always forget it is not part of VBA IsSomething functions

by  SBendBuckeye  Posted    (Edited  )
VBA provides a long list of IsSomething functions for use in testing various properties or settings in your code. I
periodically forget that I have to test for VariableName Is Nothing since VBA does not provide an IsNothing function for my use. This usually happens at the end of a long day and can be quite frustrating so I wrote my own as below:

'**********************************************************
'* Function: Returns true if argument evaluates to nothing
'* 1. IsNothing(Nothing) -> True
'* 2. IsNothing(NonObjectVariableOrLiteral) -> False
'* 3. IsNothing(ObjectVariable) -> True if instantiated,
'* otherwise False
'**********************************************************
Public Function IsNothing(pvarToTest As Variant) As Boolean
On Error Resume Next
IsNothing = (pvarToTest Is Nothing)
Err.Clear
On Error GoTo 0
End Function 'IsNothing

Enjoy!
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top