Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / April 2007

Tip: Looking for answers? Try searching our database.

Close any form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
acores - 30 Apr 2007 15:02 GMT
Hi.
I want to create a macro that closes ANY form opened when I open a new one.
Is it possible?
Thank you in advance.
Douglas J. Steele - 30 Apr 2007 15:35 GMT
The Forms collection only contains open forms, so you could loop through it,
closing everything except the current form.

Dim intLoop As Integer

 For intLoop = (Forms.Count - 1) To 0 Step -1
   If Forms(intLoop).Name <> "NameOfCurrentForm" Then
     DoCmd.Close acForm, Forms(intLoop).Name, acSaveNo
   End If
 Next intLoop

The reason for looping from the end to the front is that if you went from 0
to the end, when you deleted Forms(0), the previous Forms(1) would then
become Forms(0). When you hit the Next statement, you'd move from Forms(0)
to Forms(1), meaning that you'd never delete the form that started as form
1.

Depending on where you're calling this form, how you determine
"NameOfCurrentForm" will change.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hi.
> I want to create a macro that closes ANY form opened when I open a new
> one.
> Is it possible?
> Thank you in advance.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.