Robert
robert at servicexp.com
Sat Mar 22 08:14:29 CDT 2008
John, Thank you, I'm, generally very careful about closing and destroying created objects, but I got lazy or absent minded and end up with a very well hidden un-destroyed class holding the main class open. I finally found it... Again Thanks for your help.... WBR Robert -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Friday, March 21, 2008 10:16 PM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] Closing & Destroying Objects Class_Terminate not running means the class is not closing. The class does not close because there is still a reference to the class somewhere. The last reference to the class being set to nothing causes the VBA garbage collector to shut it down and destroy the instance, returning the memory to the pool. The only time I have ever seen something inside the class from preventing shutdown is when the class references itself. This technique is used to hold an instance open without an external pointer to the class, and this is usually only used for multiple instances of forms. If a class references itself (holds itself open) then it has to be capable of setting its self reference to nothing. Something has to trigger that or the class will never close. Again this is very rare though. More than likely you have several pointers to the class and one of them is not being set to nothing. Every single pointer to the class has to be set to nothing. The _Terminate will fire whenever that last pointer is set to nothing. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Robert Sent: Friday, March 21, 2008 8:48 PM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] Closing & Destroying Objects John, Thank you... How do you find the cause of setting a class to nothing, and the Class_Terminate sub not running.. I'm assuming something is still open within the class, but just can't see it.. Set qbc = Nothing Does not cause the Class_Terminate() sub to run.. Thanks Again. WBR Robert -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Friday, March 21, 2008 7:12 PM To: 'Access Developers discussion and problem solving' Subject: Re: [AccessD] Closing & Destroying Objects You need to set pointers to nothing EVERYWHERE. You need to close before setting pointers to nothing in the last place that the recordset is used. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Robert Sent: Friday, March 21, 2008 6:09 PM To: 'Access Developers discussion and problem solving' Subject: [AccessD] Closing & Destroying Objects Hello Group, I have a question about how to close an object correctly.. Dim rstWOS As DAO.Recordset Set rstWOS = db.OpenRecordset("qryServicesNavigator", dbOpenDynaset, dbInconsistent) I do a findfirst on rstWOS which I pass to another form. Like such.. DoCmd.OpenForm "frmMsgboxWODelete", , , , , acHidden With Form_frmMsgboxWODelete .CallingForm = "Calander" .RN = EventRN Set .rst = rstWOS .Visible = True End With In the form it's a property Private m_objRst As DAO.Recordset Public Property Set rst(objRst As DAO.Recordset) Set m_objRst = objRst End Property Where do I Properly close and destroy the recordset, in the first or the second or both? I'm thinking that I need to destroy it on the first, as if I destroy it on second via: Private Sub Form_Unload(Cancel As Integer) If Not m_objRst Is Nothing Then m_objRst.Close Set m_objRst = Nothing End If End Sub Then I get some very strange problems trying to destroy in on the first.. Like and Error 3420 Oject Invalid or No Longer Set Via: (because the recordset is already closed??) If Not rstWOS Is Nothing Then rstWOS.Close Set rstWOS = Nothing End If TIA... WBR Robert -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com