On Wed, 25 Apr 2001 13:52:32 -0400, "Tom Gilmer"
>In general, no. Copy the following into a form with a command button and
>a reference to ADO.
Tom is correct,
However if you do explicitly close objects and then destroy them (set
to nothing), the resulting program seems to run more reliably.
Also if you close recordsets and connections yourself, they are closed
the moment they are not needed, rather when VB eventually completes
the current routine. It frees up resources.
Also, although a first Connection to a database my seem slow, you will
find that if you disconnect and reconnect, it is almost instantaneous.
This is because the connections are cached. If you are developing for
a Database with many users, connecting only for the brief time you are
retreiving or writing data can help make the system very efficient.
>Private Sub Command1_Click()
>Private Sub A()
> Dim rs As ADODB.Recordset
> If rs Is Nothing Then
> MsgBox "rs doesn't exist"
> End If
> Set rs = New ADODB.Recordset
> If Not rs Is Nothing Then
> MsgBox "rs exists"
> End If
>You will see that every time you click the button, you get as msg saying
>rs doesn't exist followed by a msg telling you that it does exist. This
>is because VB destroys the rs when Sub A exits.
>However, global variables are a different story and require close
>attention since they don't go away until the form is unloaded. It a
>matter of preference but, if you are new to VB, it's probably better for
>you to explicitly destroy objects when you are finished with them.
> Set rs = Nothing (Closes it)
> Set db = Nothing (Closes it)
> - Tom
>> Do I always have to Close the DB or the Recordset after doing the
>> has to do ?