"Get in...and Get right back Out"
Does anyone have any input/comments, pros/cons, concerning the use of the following With/New methods:
With New SomeObject
'Some code
End With
Or:
With CreateObject("SomeLibrary.SomeObject"
'Some code
End With
As in:
'conn is an already opened connection to a DB
With New ADODB.Recordset
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Source = "SELECT * FROM myTABLE WHERE SomeField='SomeCriteria'"
Set .ActiveConnection = conn
.Open , , , , Options:=adCmdText
If Not .EOF Then Debug.Print .Fields(0).Value
End With
'Or simply put:
With New ADODB.Recordset
.Open "SELECT * FROM myTABLE WHERE SomeField='SomeCriteria'", conn, adUseServer, adLockOptimistic, Options:=adCmdText
If Not .EOF Then Debug.Print .Fields(0).Value
End With
Please note: There are no recordset object variables declared, and therefore, after the End With, the object is automatically destroyed.
No Close or Set/Nothing statments.
Common sense is telling me though, that the Close method should still be called prior to the End With.
What do "good programming pratices" say against the use of this With/New variant in VB?
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!