Solved

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

Posted on 2003-11-27
5
315 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
  • 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

777 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