troubleshooting Question

How to release object when I "Call getQuerydefFunction"

Avatar of Robert Berke
Robert BerkeFlag for United States of America asked on
Microsoft Access
6 Comments2 Solutions290 ViewsLast Modified:
I try to release variables after I use them.

So, I coded something as follows  (this is greatly simplified)

Code #1
  sub ChangeQueryDef(qname as string, sql as string)
    dim getChangeQueryDef as querydef
    set getChangeQueryDef = currentdb.querydefs("myname")
    .... getChangeQueryDef = sqlname
    set getChangeQueryDef = nothing
  end sub

But, I want to change the subroutine to so that it can sometimes be called as a function.
 
Code #2
  sub getChangeQueryDef(qname as string, sql as string) as querydef
    set getChangeQueryDef = currentdb.querydefs("myname")
    .... getChangeQueryDef = sqlname
    set getChangeQueryDef = nothing
  end sub

So, here is how I could use the routine and be sure the querydef variable gets de-allocated.

Code #3
   set qdf =  getChangeQueryDef("qGeneric", "select * from table")

   ... do stuff with qdf

   set qdf = nothing


But, what happense if I simnply call the routine?  My theory is the the variable does not need to be de-allocated.
But, I know that Access and Excel both sometimes create hidden variables that don't get deallocated until the application is closed.

I wonder if the following code might have that problem

Code #4
    call  getChangeQueryDef("qGeneric", "select * from table")
ASKER CERTIFIED SOLUTION
ioane
Planning & Analytics Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros