|
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 |