?
Solved

Access Functions - Best way to clean up variables at end of function

Posted on 2003-11-27
5
Medium Priority
?
338 Views
Last Modified: 2006-11-17
At the end of a function in VBA what is the "best way" to clean up variables?

1.  Close each object only.

MsSet.close
MyDB.close

2.  Set each object to nothing only.

Set MySet = Nothing
Set MyDb  = Nothing

3. Set ONLY the DB variable to Nothing, even though other variables have been used.

Set MyDB = Nothing

4. Close all variables and then set to nothing

MsSet.close
MyDB.close

Set MySet = Nothing
Set MyDb  = Nothing


Please also tell me why you are suggesting an option.

Thanks.




0
Comment
Question by:hertzgordman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 32

Expert Comment

by:jadedata
ID: 9832736
Hey hertzgordman!

  I do it this way
  rs.close: set rs = nothing
  db.close: set db = nothing

I always try to destroy the objects from the child level up.

regards
Jack
0
 

Author Comment

by:hertzgordman
ID: 9832768
I like your approach.

But please tell me that would be the consequence of NOT setting the objects to nothing.

I have a whole bunch of functions where I am NOT doing this.  Do I need to go back and fix them?
0
 
LVL 32

Accepted Solution

by:
jadedata earned 1000 total points
ID: 9832796
Having "undestroyed" data access objects (Access recordsets/databases) in memory has been alledged to cause Access to remain in memory even after a quit.  It has also been blamed for "insufficient memory" issues.

All I know is that my teacher told me to do it,... it doesn't cost me anything...so I do it.
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9832808
I would recommend that you correct this "when you are in the neighborhood".  I wouldn't make a huge effort to try and find them all unless you are experiencing memory issues or Access remains in the task manager list after application.quit
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9833078
thanx!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question