We help IT Professionals succeed at work.
Get Started

How to release object when I "Call getQuerydefFunction"

rberke
rberke asked
on
289 Views
Last Modified: 2012-05-09
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")
Comment
Watch Question
Planning & Analytics Manager
Commented:
This problem has been solved!
Unlock 2 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE