In your code example, the object will always be Nothing
, because this is the last action. Here's how it should be:
Function getObject(str) If ... Then Set getObject = object_goes_here Exit Function End If Set getObject = Nothing End Function
or
Function getObject(str) Set getObject = Nothing If ... Then Set getObject = object_goes_here End If End Function
GSerg's answer is correct: you should use Nothing. Also, to see if the object has a null reference, use:
If Not object Is Nothing Then ' do something End If
AutomatedChaos
source share