Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cleaning Up Your Code

Status
Not open for further replies.

SgtJarrow

Programmer
Apr 12, 2002
2,937
US
OK, code gurus.....

Simple question....Which is better to "clean up" your code at the end of a procedure and why:

Set rs = Nothing

or

rs.Close

Any other suggestions for "properly" closing down a procedure? Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Well I always add the code in my procedure to close recordset objects etc that are declared in the closing procedure but you have to remember that whether you implicitly add the code or not once you exit a procedure that declares Connection, Database, or Recordset objects, those objects are closed automatically. Regards,
gkprogrammer
 
Maybe it's becuase I'm paranoid (or at least you guys all think I am, ha ha) but I sometimes put both the
Code:
Set
and
Code:
Close
statements in.

Having said that, I would imagine
Code:
rs.Close
tp be sufficient. GKProgrammer makes a good point to put it in your Exit code, so that the closure still happens even if you "shortcut" to the Exit code via an error handler.

For an ADO recordset you could use its
Code:
State
property in your Exit code to only close the recordset if it's open, which is quite neat.


[pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top