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")
Our community of experts have been thoroughly vetted for their expertise and industry experience.