understand a closed object conn

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

understand a closed object conn

Post by sal21 »

I i use a conn similar:

...
Set CONN = New ADODB.Connection
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\....
...

i need to use:

conn.close
set conn=nothing

to the and of code, or the satatement Set CONN = New ADODB.Connection automaticlly destroyed all conn object???

note:
i use the conn recursivlly

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: understand a closed object conn

Post by HansV »

You should close the connection before opening a new one, but if you use Set conn = New ADODB.Connection, you don't need to use Set Conn = Nothing before that. So either use

conn.Close
Set conn = Nothing

when you don't need conn any more, or

conn.Close
Set conn = New ADODB.Connection

when you want to create a new connection.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: understand a closed object conn

Post by sal21 »

HansV wrote:You should close the connection before opening a new one, but if you use Set conn = New ADODB.Connection, you don't need to use Set Conn = Nothing before that. So either use

conn.Close
Set conn = Nothing

when you don't need conn any more, or

conn.Close
Set conn = New ADODB.Connection

when you want to create a new connection.
now all is clear!
tks.