LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default using CLOSE and NOTHING


Dion Wrote:
I am wondering if there is a preferred way of creating objects (if tha
is
the right word). For example, I am using:

Dim cnn1 As ADODB.Connection
Set cnn1 = New ADODB.Connection

I know I could also use:
Dim cnn1 As New ADODB.Connection

I understand both do the same thing? Are there scenarios where one is
preferred
over the other, or simply a personal choice?

Also, I am more interested in the proper use of "close" and "set objec
to
nothing"
In my above code, at the end I have:
cnn1.Close
Is this all I need to do? Should I also have:
Set cnn1 = Nothing
Does using close without set = nothing leave anything open?

Thanks!
Dion


The two line one is preffered but only because it's easier to read

Code
-------------------
Dim cnn1 As ADODB.Connection
Set cnn1 = New ADODB.Connectio
-------------------


You shoul use both .close (first) and set to nothing.
Why?
.close let's vba know the connection is closed and some buffers an
error checking is done. But as Microsoft is Microsoft due to a glitc
it does not relaase the memory used by this variable ans setting t
nothing reeases this chunk of memory.
Setting to nothing without closing can lock up your database becaus
record set wasn't closed

Rule ot thumb:
close and set to nothing objects in the reverse order you've have se
them.

so first the recordset(s) and then the database for example

--
Dnere
-----------------------------------------------------------------------
Dnereb's Profile: http://www.excelforum.com/member.php...fo&userid=2618
View this thread: http://www.excelforum.com/showthread.php?threadid=39953

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why excel close all files when I just want to close one files hon123456 Excel Discussion (Misc queries) 2 December 8th 10 12:12 PM
why do all excel worksheets/workbooks close when I close one? Penny Excel Discussion (Misc queries) 1 November 29th 06 03:49 AM
close button does not close goplayoutside Excel Discussion (Misc queries) 1 October 11th 05 03:42 PM
Excel shoud not close all active books when clicking close button technomike Excel Discussion (Misc queries) 0 June 10th 05 05:35 PM
excel - Windows close button (x) should only close active workboo. CoffeeAdict Setting up and Configuration of Excel 3 February 8th 05 04:30 AM


All times are GMT +1. The time now is 08:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"