Simple Question 
Author Message
 Simple Question

In general, no. Copy the following into a form with a command button and
a reference to ADO.

'********
Option Explicit

Private Sub Command1_Click()
  A
End Sub

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
End Sub

'********

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



Quote:
> Do I always have to Close the DB or the Recordset after doing the
stuff it
> has to do ?

> Thanks
>     Philip



Mon, 13 Oct 2003 01:52:32 GMT  
 Simple Question
Do I always have to Close the DB or the Recordset after doing the stuff it
has to do ?

Thanks
    Philip



Mon, 13 Oct 2003 01:12:57 GMT  
 Simple Question
On Wed, 25 Apr 2001 13:52:32 -0400, "Tom Gilmer"

Quote:

>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.

Richard.

Quote:
>'********
>Option Explicit

>Private Sub Command1_Click()
>  A
>End Sub

>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
>End Sub

>'********

>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
>stuff it
>> has to do ?

>> Thanks
>>     Philip



Mon, 13 Oct 2003 07:33:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Simple Question: Assigning Icon to an App : Simple Question

2. simple question...what was the source code for this simple custom action (rules wizard)

3. SIMPLE QUESTION : SIMPLE ANSWER?

4. SIMPLE QUESTION : SIMPLE ANSWER?

5. SIMPLE QUESTION, please SIMPLE ANSWER

6. Simple controls and a very simple question

7. Simple Question...simple answer???

8. VB5 Pro Masked Edit control - A simple, simple question

9. HELP! simple question need simple answer

10. HELP! simple question need simple answer

11. HELP! simple question need simple answer

12. Simple Question (dumb Question)

 

 
Powered by phpBB® Forum Software