Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now