OK, I think I understand now.
To close and clean up an ADO connection, you'd do something like this:
[tt]
If Not objADORecordset is Nothing Then
[tab]If objADORecordset.State = adStateOpen Then
[tab][tab]objADORecordset.Close
[tab]End If
[tab]Set objADORecordset= Nothing
End If
Set objADOCommand = Nothing
If Not objADOConnection is Nothing Then
[tab]If objADOConnection .State = adStateOpen Then
[tab][tab]objADOConnection .Close
[tab]End If
[tab]Set objADOConnection = Nothing
End If
[/tt]
So, if the recordset object exists, you test to see if it's still open. If it is, you close it. You then set it to Nothing (which frees the memory it used). With an ADO Command object, you don't close it, so you just set it to nothing. No need to test to see if it exists, as it's always OK to set an object variable to Nothing, even if it's already Nothing. The ADO Connection object gets freed the same way as the Recordset object.
The way you use this code is by setting up an error handler in your code:
[tt]
Public Function MyFunction() as Boolean
[tab]Dim objADORS as ADODB.Recordset
[tab]On Error Goto MyFunction_ErrHandler
[tab]MyFunction = False 'Assume failure
[tab]Set objADORS = New ADODB.Recordset
[tab]' code that does stuff goes here
[tab]MyFunction = True
[tab]Goto MyFunction_Cleanup
MyFunction_ErrHandler:
[tab]'Code to log errors
[tab]' Fall through into cleanup
MyFunction_Cleanup:
[tab]' Code like I showed you above to
[tab]' clean up objects
End Function
[/tt]
Hope this helps.
Chip H.