Solved

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

Posted on 2003-11-27
5
335 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 250 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

Industry Leaders: 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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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