dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Jul 9, 1999

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Make Sure all Access QueryDef Objects are Closed

When you're working with QueryDef (SQL instructions stored on an MDB database) and open it, DAO loads all the QueryDefs. For example, if you have an MDB with five QueryDefs named qryCustomers, qryOrders, qryContacts, qrySales, and qryPersons, and you want to use the qryCustomers, do this:

 
Dim qdCustomer as QueryDef
Dim rsCustomer as RecordSet

	Set qdCustomer= Db.QueryDefs("qryCustomers")
	qdCustomer.Parameters![Custom ID]= 195
	Set rsCustomer= qdCustomer.OpenRecordSet(dbReadOnly)
		While not rsCustomer.Eof
			txtCustomerName= rsCustomer!Name
				...........
			rsCustomer.MoveNext
		Wend

		rsCustomer.Close 'Close it
		set rsCustomer=Nothing
		'Free the reference to rsCustomer

		qdCustomer.Close 'Close it
		set qdCustomer =  Nothing
		'Free the reference to qdCustomer

The problem is that DAO only closes the qdCustomer, but the other four QueryDefs (qryOrders, qryContacts, qrySales, and qryPersons) remain open. To solve the problem, use this subroutine:

 
Public Sub ToNothing()
Dim qdGeneric as QueryDef

	'Surf the QueryDefs Collection
	For each qdGeneric in Db.QueryDefs
		qdGeneric.close 'Close it
		Set qdGeneric = Nothing 
	Next

End Sub

	Now put the call to the subroutine ToNothing:
	.
	.
	.
rsCustomer.Close
Set rsCustomer = Nothing
ToNothing
Gonzalo Medina
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date