Variable cleanup

  • Thread starter Thread starter Question Boy
  • Start date Start date
Q

Question Boy

Hello,

I know that when I create code using DAO I need to cleanup after my
variables.... set db = nothing .... What about when simply usig recordset
clone?

For instance I have an On_Click event which is comprised of

Dim rst As Recordset

Set rst = Me.RecordsetClone
With rst
.MoveFirst
Do While Not .EOF
.Edit
rst![ApproGestion] = False
.Update
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing

Is this proper? Is the rst.close and set rst = nothing required, a good
idea, not neccessary?

Thank you for the insight.

QB
 
It's a good idea.

VBA is supposed to clean up after itself, but problems have been known to
occur sometimes, so I always do my own cleanup.
 
Question Boy said:
Hello,

I know that when I create code using DAO I need to cleanup after my
variables.... set db = nothing .... What about when simply usig recordset
clone?

For instance I have an On_Click event which is comprised of

Dim rst As Recordset

Set rst = Me.RecordsetClone
With rst
.MoveFirst
Do While Not .EOF
.Edit
rst![ApproGestion] = False
.Update
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing

Is this proper? Is the rst.close and set rst = nothing required, a good
idea, not neccessary?


The "Set rst = Nothing" is good practice, though it's not *supposed* to be
necessary. I don't think you should close the RecordsetClone, though.
 
Back
Top