Hoping for short cut key to close vba windows in Access

pcalabria used Ask the Experts™
I'm getting so tired of x' ing out of all of those visual basic windows in MS Access code view.
Had the same problem with A2K.. now using Office 365... have they added a function key or key shortcut for this yet???
I can't believe you experts deal with this problem..do you?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017

If your app keeps dropping into code windows, it is because you are not trapping errors correctly.  From the VBA window, go to Tools/Options and look at the error trapping setting on the General Tab.  Mine is set to break on unhandled errors.   As I discover potential errors, I either fix them permanently if my code is the problem or add handlers to give users help in recovering from the problem without dropping into code.
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and Programming
Top Expert 2015

here is some code you can use to close open modules in VBA:

VBA > Module > Close Open Windows

Daniel PineaultPresident / Owner CARDA Consultants Inc.
Distinguished Expert 2018

How exactly does it impact you if another window is open underneath the one you are working on?  If they are maximized, you only see the one you are working on.  I guess I'm just used to it.

Regardless, Mz-Tools add-in has a close all modules button amongst many other very valuable commands, definitely worth the price.

If you just want code, try
 Public Sub VBE_CloseAllModules(_
     Dim i As Integer
     Dim mods As Modules
     Set mods = Application.Modules
     For i = mods.count - 1 To 0 Step -1
         DoCmd.Close acModule, mods(i).Name, acSaveYes
     Next i
 End Sub

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2015
Distinguished Expert 2018
Press and hold down Ctrl+F4.
Daniel PineaultPresident / Owner CARDA Consultants Inc.
Distinguished Expert 2018

Nice little trick Gustav!


Thanks!  It closes the windows one at a time but sure beats using the mouse!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial