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 QueryDefDim 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 	NextEnd Sub	Now put the call to the subroutine ToNothing:	.	.	.rsCustomer.CloseSet rsCustomer = NothingToNothing
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS