A
alex
When to close QueryDef
Hello,
I have a form in which users run a variety of queries (built
dynamically based on what gets entered/clicked on the form) through a
query def with linked SQL Server tables.
The code looks like this:
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’
With dbs
Set qdf = .CreateQueryDef("", MyQuery())
qdf.ODBCTimeout = Me.TimeOut 'combo box that holds time intervals
qdf.Execute 'run query
qdf.Close
End With
Set qdf = Nothing 'clean up
Set dbs = Nothing 'clean up
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’
The user could run one query or 100 queries before closing the form;
i.e., looping through the query def 100 times! Every time the user
runs a query, it loops through the code above.
My question is: when should I close the qdf (like I have above or when
the form closes)? Also, when/if should I set qdf = nothing. Also,
had I named the query def, when should it be deleted?
I know the generic answer is after I’m finished, but I’m technically
not finished with it until the form closes. I want the query to be as
fast as possible…
Thanks,
alex
Hello,
I have a form in which users run a variety of queries (built
dynamically based on what gets entered/clicked on the form) through a
query def with linked SQL Server tables.
The code looks like this:
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’
With dbs
Set qdf = .CreateQueryDef("", MyQuery())
qdf.ODBCTimeout = Me.TimeOut 'combo box that holds time intervals
qdf.Execute 'run query
qdf.Close
End With
Set qdf = Nothing 'clean up
Set dbs = Nothing 'clean up
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’
The user could run one query or 100 queries before closing the form;
i.e., looping through the query def 100 times! Every time the user
runs a query, it loops through the code above.
My question is: when should I close the qdf (like I have above or when
the form closes)? Also, when/if should I set qdf = nothing. Also,
had I named the query def, when should it be deleted?
I know the generic answer is after I’m finished, but I’m technically
not finished with it until the form closes. I want the query to be as
fast as possible…
Thanks,
alex