Hi
Is there a way to test if a variable or an object exists?
Hi
Is there a way to test if a variable or an object exists?
Sub test()
Dim obc As Object
On Error Resume Next
a = obc
If Err.Number <> 0 Then
'code in here
End If
On Error GoTo 0
End Sub
thanks gerken.
However, it doesn't solve my challenge. I'm using different forms that share some procedure. The forms do not all have exactly the same objects and variables.
I am using an error catch at present, but was hoping there is a single command that one can use to test if an object actually exists. (Visual dBase does have such a command)
For variables, check the value. You should always use Option Explicit as the first line of code in a Module or Userform and avoid variables existing or not.
For objects, use Is Nothing or Is Not Nothing. e.g.
http://www.vbaexpress.com/forum/showthread.php?t=38802
In that case you can use a classmodule.I'm using different forms that share some procedure