Make Sure all Access QueryDef Objects are Closed

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several