Variable cleanup

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
 
D

Douglas J. Steele

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

Dirk Goldgar

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top