'Loose' declaration 're-discovery'
I just want to share what I have 're-discovered'... Its a disadvantage of 'loose' declaration of objects...
Case 1:
VB Code:
Private Sub Command1_Click()
Dim x As New ADODB.Recordset
Set x = Nothing
'Will return false
MsgBox x Is Nothing
End Sub
Private Sub Command2_Click()
Dim x As ADODB.Recordset
Set x = New ADODB.Recordset
Set x = Nothing
'Will return true
MsgBox x Is Nothing
End Sub
Case 2:
VB Code:
'In Form1
Option Explicit
Private Sub Command1_Click()
Form2.ObjectsAreLoaded
End Sub
'In Form2
Option Explicit
Private adoRecordset1 As New ADODB.Recordset
Private adoRecordset2 As ADODB.Recordset
Public Sub ObjectsAreLoaded()
'Will return false = means object is instantiated
MsgBox adoRecordset1 Is Nothing
'Will return true = means object is not yet instantiated
MsgBox adoRecordset2 Is Nothing
End Sub
Re: 'Loose' declaration 're-discovery'
In case anyone is wondering. That is because when you use loose binding, as soon as you reference the object, VB checks to see if it exists. If not then it creates it, which is why, as dee-u has shown above, you cannot test to see if it is Nothing, because even if you have explicitly destroyed it when the test is executed the object is created.