Barbara Ryan
BarbaraRyan at cox.net
Fri Aug 19 15:09:45 CDT 2005
Forms.Count is equal to the number of open forms, so if 3 forms are open, the For loop executes 3 times.. Barb ----- Original Message ----- From: "Hale, Jim" <Jim.Hale at FleetPride.com> To: "'Access Developers discussion and problem solving'" <accessd at databaseadvisors.com> Sent: Friday, August 19, 2005 3:35 PM Subject: RE: [AccessD] Close All Forms > Aren't you iterating through the entire forms collection? So even if a form > is closed you are attempting to close it? > How about > Function CloseAllForms() > Dim i As Integer, strFrmName as string > ' Loop through the collection of open forms and close them (except > for the main menu) > If Forms.Count > 0 Then > For i = Forms.Count - 1 To 0 Step -1 > strFrmName=Forms(i).Name > If strFrmName <> "frmMainMenu" Then > If IsFormOpen(strFrmName)= true then DoCmd.Close > acForm, strFrmName > End If > Next i > End If > End Function > > Public Function IsFormOpen(strFormName As String) As Boolean > On Error GoTo PROC_ERR > > IsFormOpen = (SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0) > > PROC_EXIT: > Exit Function > > PROC_ERR: > MsgBox "Error: " & Err.Number & ". " & Err.Description, , _ > "IsFormOpen" > Resume PROC_EXIT > > End Function > > Jim Hale > > -----Original Message----- > From: Barbara Ryan [mailto:BarbaraRyan at cox.net] > Sent: Friday, August 19, 2005 2:11 PM > To: Access Developers discussion and problem solving > Subject: Re: [AccessD] Close All Forms > > > It dies after the "End Function" line is executed. > > > ----- Original Message ----- > From: "Josh McFarlane" <darsant at gmail.com> > To: "Access Developers discussion and problem solving" > <accessd at databaseadvisors.com> > Sent: Friday, August 19, 2005 2:50 PM > Subject: Re: [AccessD] Close All Forms > > > > On 8/19/05, Barbara Ryan <BarbaraRyan at cox.net> wrote: > > > I have used the following code successfully in Access 97 to close all > forms when a specific function key is pressed. However, in Access 2002, > this code causes the error box to appear (with the 2 options to send an > error report to Microsoft or not) and then closes Access. Does anyone know > why? > > > > > > Function CloseAllForms() > > > Dim i As Integer > > > ' Loop through the collection of open forms and close them > (except for the main menu) > > > If Forms.Count > 0 Then > > > For i = Forms.Count - 1 To 0 Step -1 > > > If Forms(i).Name <> "frmMainMenu" Then > > > DoCmd.Close acForm, Forms(i).Name > > > End If > > > Next i > > > End If > > > End Function > > > > Can you trace the specific line that it dies on? (IE Set a breakpoint > > on DoCmd and see if it ever fires for each form.) > > > > -- > > Josh McFarlane > > > > "Peace cannot be kept by force. It can only be achieved by understanding." > > -Albert Einstein > > -- > > 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 > > *********************************************************************** > The information transmitted is intended solely for the individual or > entity to which it is addressed and may contain confidential and/or > privileged material. Any review, retransmission, dissemination or > other use of or taking action in reliance upon this information by > persons or entities other than the intended recipient is prohibited. > If you have received this email in error please contact the sender and > delete the material from any computer. As a recipient of this email, > you are responsible for screening its contents and the contents of any > attachments for the presence of viruses. No liability is accepted for > any damages caused by any virus transmitted by this email. ---------------------------------------------------------------------------- ---- > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com >