A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can I close all open forms?



 
 
Thread Tools Display Modes
  #1  
Old October 7th, 2004, 01:38 PM
DBS
external usenet poster
 
Posts: n/a
Default Can I close all open forms?

There isn't a straightforward command to close all forms
that are open, so you'd have to create one of your own.
But it's simple to loop through the Forms collection to
close them all:
'==================================
Public Function CloseAllOpenForms()

Dim frm As Form

For Each frm In Forms
DoCmd.Close acForm, frm.Name
Next frm

End Function
'==================================

Hope that helps!

DBS (David Staas)

-----Original Message-----
Hi

I have various menu options which open forms then other

forms etc . Instead
of issuing DoCmd.Close for each is there a command to

close all forms or a
specified number of forms?

Tx for any help


Sheila
.

  #2  
Old October 7th, 2004, 02:19 PM
Sheila D
external usenet poster
 
Posts: n/a
Default

Hi David

Tx for this - I have set up the module but how do I then write the code to
run it as the On Click event - I'm not a very experienced VB person. I tried
doing it as a macro using Run COde command but for some reason I had to click
the button twice before it would work.

Tx

SHeila

"DBS" wrote:

There isn't a straightforward command to close all forms
that are open, so you'd have to create one of your own.
But it's simple to loop through the Forms collection to
close them all:
'==================================
Public Function CloseAllOpenForms()

Dim frm As Form

For Each frm In Forms
DoCmd.Close acForm, frm.Name
Next frm

End Function
'==================================

Hope that helps!

DBS (David Staas)

-----Original Message-----
Hi

I have various menu options which open forms then other

forms etc . Instead
of issuing DoCmd.Close for each is there a command to

close all forms or a
specified number of forms?

Tx for any help


Sheila
.


  #3  
Old October 7th, 2004, 02:37 PM
Douglas J. Steele
external usenet poster
 
Posts: n/a
Default

Actually, there are problems using For Each frm In Forms in this case.

When you close the first form, the pointer is set to the next form. The Next
frm at the end of the loop advances you again, so you end up skipping what
was originally the 2nd form.

Use the following instead:

Public Function CloseAllOpenForms()

Dim frm As Form
Dim intLoop As Integer

For intLoop = (Forms.Count - 1) To 0 Step -1
Set frm = Forms(intLoop)
DoCmd.Close acForm, frm.Name
Next intLoop

End Function



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


"Sheila D" wrote in message
...
Hi David

Tx for this - I have set up the module but how do I then write the code to
run it as the On Click event - I'm not a very experienced VB person. I

tried
doing it as a macro using Run COde command but for some reason I had to

click
the button twice before it would work.

Tx

SHeila

"DBS" wrote:

There isn't a straightforward command to close all forms
that are open, so you'd have to create one of your own.
But it's simple to loop through the Forms collection to
close them all:
'==================================
Public Function CloseAllOpenForms()

Dim frm As Form

For Each frm In Forms
DoCmd.Close acForm, frm.Name
Next frm

End Function
'==================================

Hope that helps!

DBS (David Staas)

-----Original Message-----
Hi

I have various menu options which open forms then other

forms etc . Instead
of issuing DoCmd.Close for each is there a command to

close all forms or a
specified number of forms?

Tx for any help


Sheila
.




  #4  
Old October 7th, 2004, 04:35 PM
Sheila D
external usenet poster
 
Posts: n/a
Default

Wow, works a treat

Thanks very much

Sheila

"Douglas J. Steele" wrote:

Actually, there are problems using For Each frm In Forms in this case.

When you close the first form, the pointer is set to the next form. The Next
frm at the end of the loop advances you again, so you end up skipping what
was originally the 2nd form.

Use the following instead:

Public Function CloseAllOpenForms()

Dim frm As Form
Dim intLoop As Integer

For intLoop = (Forms.Count - 1) To 0 Step -1
Set frm = Forms(intLoop)
DoCmd.Close acForm, frm.Name
Next intLoop

End Function



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


"Sheila D" wrote in message
...
Hi David

Tx for this - I have set up the module but how do I then write the code to
run it as the On Click event - I'm not a very experienced VB person. I

tried
doing it as a macro using Run COde command but for some reason I had to

click
the button twice before it would work.

Tx

SHeila

"DBS" wrote:

There isn't a straightforward command to close all forms
that are open, so you'd have to create one of your own.
But it's simple to loop through the Forms collection to
close them all:
'==================================
Public Function CloseAllOpenForms()

Dim frm As Form

For Each frm In Forms
DoCmd.Close acForm, frm.Name
Next frm

End Function
'==================================

Hope that helps!

DBS (David Staas)

-----Original Message-----
Hi

I have various menu options which open forms then other
forms etc . Instead
of issuing DoCmd.Close for each is there a command to
close all forms or a
specified number of forms?

Tx for any help


Sheila
.





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Forms Using Parameter Query AR New Users 2 October 11th, 2004 04:11 PM
How to get weekly open high low close from a range of data? Herbert Chan Charts and Charting 6 September 18th, 2004 02:48 AM
How to get weekly open high low close from a range of data? Herbert Chan General Discussion 0 September 16th, 2004 03:24 AM
How do I close some Excel files and leave others open without sav. bevomom General Discussion 1 September 14th, 2004 04:11 PM
Open Macro after Close Gerry Kuta Worksheet Functions 1 October 23rd, 2003 02:25 PM


All times are GMT +1. The time now is 10:28 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.