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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
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 |