Re: Is setting to Nothing really necessary if procedure is about to end?



"Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx> wrote in
news:446f433d$0$31515$5a62ac22@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:

In Access 97, there were 2 bugs that meant you could not close the
database. When you tried, it would minimize to the task bar, but
not close. You had to use Ctrl+Alt+Del to shut it down.
Ultimately, the 2 bugs were tracked down to:
a) referring to a boolean control (check box, toggle button,
option button) without explicitly specifying its Value property

Actually, that is one of the workarounds, not the source of the
problem.

The source of the problem was an implicitly created by reference
call that couldn't be destroyed. If you surrounded the Boolean
control call with parens to force evaluation, it would solve the
problem, too, because it was causing the value to be used rather
than a reference to the control.

This is actally another instance of the same problem, of references
not being released when code goes out of scope, and is a direct
result of VBA's reliance on reference counting for cleanup of
variables -- implicit references don't always get properly managed
in the code that keeps track of them.

Another example of where it's good to be explicit about this is in
any FOR/EACH loop that uses an object variable, such as:

For Each ctl In Me.Controls
...
Next
Set ctl = Nothing

For Each fld In rs.Fields
...
Next
Set fld = Nothing

And so forth.

I started doing this on MichKa's advice.

Lyle has frequently pointed out that the ADO libraries don't have
this problem with VBA, so you don't need to worry about cleaning up
your ADO object variables. However, were I to use ADO in VBA, I
would clean up, anyway, even though it's strictly speaking
unnecessary, simply because I think it's good practice to write code
that cleans up after itself even when the automated garbage
collection routines work reliably.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
.



Relevant Pages

  • Re: Using ADO and Late Binding
    ... but it is possible to use ADO with early binding. ... Note that the .xla is saved with a low ADO version reference. ... Dim ADOConn As Object ... Dim strADOFile As String ...
    (microsoft.public.excel.programming)
  • RE: Built in function errors.
    ... located on other tabs in a tab control. ... I had to find a way to use the reference. ... TLBs on the client computer. ... reselect libraries simply makes the application not worth building using ...
    (microsoft.public.access.modulesdaovba)
  • Re: Writing Access functions
    ... passing values by Value or by Reference. ... Public Function NameFromIDAs String ... If you pass a control reference: ...
    (microsoft.public.access.modulesdaovba)
  • Re: Reference forms and fields with variables
    ... There are so many ambiguities here, that it may not really help to follow ... If Field2 is a field in the underlying recordset, ... but the reference is unstable. ... LinkChildFields property of a subform is NOT represented by a control in the ...
    (microsoft.public.access.formscoding)
  • RE: f7s4r4v
    ... speaking this is a reference to the current instance of the class, ... Similarly any references to a control on the form simply by the ... Private Sub Form_AfterUpdate ... intSecond As Integer) ...
    (microsoft.public.access.gettingstarted)