Martin Caro
mcaro at bigpond.net.au
Sun Mar 28 05:05:37 CST 2004
Thanks Gustav That did the trick....another technique learnt! Martin ----- Original Message ----- From: "Gustav Brock" <gustav at cactus.dk> To: "Access Developers discussion and problem solving" <accessd at databaseadvisors.com> Sent: Sunday, March 28, 2004 7:37 PM Subject: Re: [AccessD] Closing Forms > Hi Martin > > > At times I have 3 or 4 forms open at once and may want to return to the main menu form from any of those and at the same time closing all forms except the main menu form. Can anyone tell me why the > > following function after closing only one form via the Case else will not continue to work through the forms group and close multiple forms? > > > Public Function CloseForms(FromForm As String) > > Dim frm As Form > > For Each frm In Forms > > Select Case frm.Name > > Case Is = "frmMainMenu" > > 'Dont close it > > Case Is = FromForm > > 'Dont close the form that called this yet > > Case Else > > 'Close any other form > > MsgBox ("The form being closed is " & frm.Name) > > DoCmd.close acForm, frm.Name, acSaveNo > > End Select > > Next frm > > End Function > > You are probably destroying the collection Forms moving forwards. > Most solutions to this task browse backwards through the collection > like this: > > <code> > > Public Function CloseForms(FromForm As String) > > Dim strForm As String > Dim lngForm As Long > > For lngForm = Forms.Count - 1 To 0 Step -1 > strForm = Forms(lngForm).Name > Select Case strForm > Case Is = "frmMainMenu" > 'Dont close it > Case Is = FromForm > 'Dont close the form that called this yet > Case Else > 'Close any other form > MsgBox ("The form being closed is " & strForm) > DoCmd.close acForm, strForm, acSaveNo > End Select > Next > > End Function > > </code> > > /gustav > > -- > _______________________________________________ > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com