Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Close Form > < Combining Names | Split Commissions >
Close Form
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   5 years ago

Close an Open Form using DoCmd.Close


 S  M  L  XL  FS  |  Slo  Reg  Fast  2x  |  Bookmark Join Now

In this video I'm going to teach you how to close one form when another is closed. It involves ONE line of VBA coding, but don't be afraid. I'll show you exactly how to do it.

Claudia from Henderson, Nevada (a Platinum Member) asks: I have a couple of "additional info" forms that I can open for a customer, such as their contacts, orders, service calls, etc. I like to keep these as separate forms much like you do in your Free Customer Template. It's a pain to have to close them all individually whenever I'm done with a customer. Is there a way to link them all so they close whenever I close the customer form?

Members

Members will learn how to loop through ALL open forms and close them, except for the Main Menu form.

Silver Members and up get access to view Extended Cut videos, when available. Gold Members can download the files from class plus get access to the Code Vault. If you're not a member, Join Today!

Links

Learn More

FREE Access Beginner Level 1
FREE Access Quick Start in 30 Minutes
Access Level 2 for just $1

Free Templates

TechHelp Free Templates
Blank Template
Contact Management
Order Entry & Invoicing
More Access Templates

Resources

Diamond Sponsors - Information on our Sponsors
Mailing List - Get emails when new videos released
Consulting - Need help with your database
Tip Jar - Your tips are graciously accepted
Merch Store - Get your swag here!

Questions?

Please feel free to post your questions or comments below or post them in the Forums.

Keywords

microsoft access, ms access, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #instruction, #learn, #lesson, #training, #database, onclose, on close, on close event, close form, closeform, close all open forms, loop through forms, loop through all forms, close all forms

 

Comments for Close Form
 
Age Subject From
7 monthsClose FormSarah Bliss

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to Close Form
Get notifications when this page is updated
 
Intro In this video, I will show you how to use VBA in Microsoft Access to close multiple related forms automatically when you close a main form, using the DoCmd.Close command and the On Close event. We will walk through step-by-step how to write the code, where to place it, and discuss form settings like Navigation Buttons and Modal forms to help manage user interaction with multiple open forms.
Transcript Welcome to another TechHelp video brought to you by AccessLearningZone.com. I am Richard Rost, your instructor.

In this video, I'm going to show you how to close an open form in Microsoft Access using the DoCmd.Close VBA command and an on-close event. Now, do not be scared. Yes, it's one line of code. If you want to close a form that's based on another form, I'm going to show you how this works in just a second.

Today's question comes from Claudia from Henderson, Nevada, one of my platinum members. Claudia says, "I've got a couple of additional info forms that I can open for a customer, like their contacts, orders, service calls, etc. I like to keep these as separate forms, much like you do in your free customer template. It's a pain to have to close them all individually whenever I'm done with a customer. Is there a way to link them all so they close whenever I close the customer form?"

Well, Claudia, unless you make them subforms inside of another form, then there's really no way to link two forms together without using VBA code. The good news is, you can do it with literally one line of code in your VB. I'll show you how to do it in just a second. It's real simple.

I get it though. I understand why you like to keep them as separate forms. You can resize them. You can move them, that kind of stuff. For those of you who do not know what Claudia is talking about, if you've got the customer list here, that's one form. You can use this to open another form. Here's the customers form. Here you can open up the orders. You can open up contacts. She's got a couple of other forms. She showed me a picture of her database. Most of them are different things like service calls and so on like that.

What she's saying is when she's done with customers, she wants to just close the customer form and then it takes all these other related forms with it. There's no way to do that without code, but it's real simple. It's one line of code. You just have to know where to put that one line of code. It's kind of like the Tesla story that I have on my website. I'll put a link down below if you're curious.

Now, if you've never done any VBA before, go watch this video first. I'll put a link down below in the link section, my intro to VBA. It's not that long. It teaches all the basics you need to know to use Access VBA. But even if you don't want to watch that, I'm going to walk you through it step by step. All right, it's real simple. Here we go.

All right, so here I am back in the database. Okay, let's bring up our customer form. From here I've got two other forms: orders, and I've got contacts. Now if I've got both of these open and I close the customer form, I want it to also close the contacts and the orders form. That means on the customer form, I need an event that runs when this form closes. The event is called On Close.

Go to Design View, right click, Design View. Open up the form's properties right there, double click, go to the Events tab. Now find On Close, it's right down here On Close. Do not click the down arrow, click the dot dot dot button. When you do that, you might get a little window up that says what kind of builder do you want. I have that turned off on mine. I talk about this in the intro to VBA class. Just pick the code builder.

Code builder will put you right here in the VBA editor in the form close event. All you're going to do is come in here and type in this command. It's real simple. DoCmd.Close, space, what kind of object are you trying to close. There's a list of them right here, pick acForm, all right, Access form. Comma, what's the name of the object you want to close? Let's close the contact form. So ContactF, comma, and then you have the option to prompt the user to save if you've made design changes. Like if you've changed the design in the form, there's no prompt or yes. I'm just going to go acSaveYes. That will save any design changes.

The reason why I say yes is mostly for me. If I've made a design change and forgot to save it, I want it to save those changes. My end users will never work with a version of the database they can actually modify. So even if it says acSaveYes, they can't make design changes anyway. So that's never an option.

So let's save this, control S. Now I'm going to go back to the database. Let's close this down, reopen the customer form. Now let's open contacts, that's the ContactF. Come back over here. Now I'm going to close this form and look at that. It took it down with it. See that? Open up customer form. If contacts happens to be open and I come back over here and I close the customer form, it closes both forms. See that? One line of code to do that. Real simple.

I want to do it for the order form as well. Here's the order form. I believe that's OrderF right there. Let's go back into the code. Right click, Design View. Open up the properties. On Close event, click on the dot dot dot right there. That brings you right back in here. We'll put one more line right below it: DoCmd.Close acForm, "OrderF", acSaveYes. Save it. Come back over here. Close this all down. Shut everything down between runs. Open it back up again. Let's open up the order form. Let's go back here and open up the contacts form. Let's move that over there for now. Ready and close it down. See? It shut down all the related forms. Nice and simple.

See, one line of code to close another form. You just have to know where to put it. You have to get in there and put it in the right spot. There are all kinds of different events that you can use in here that run. If you open this up again, come into the event tab. It's On Current that happens when you move from record to record or when you load the form the first time. On Load when the form loads, On Open when it opens. There is a slight difference in those, but I cover those in my full classes. Basically, there are events that run when you do pretty much everything: when you add a new record, when you delete a record, all kinds of stuff.

Now you can see that if my other forms are open and I close the customer form, they shut down. See that?

One thing you do have to be careful of though is if you open up the order form, for example, and then come back here and go to a different customer, see that? Then this doesn't change. You could put an On Current event in there that will open up the orders for that customer. It's a little more complicated. I do cover that in my full classes. One thing you could do is simply turn off the navigation buttons down here.

Watch this. Let me close this guy. Right click, Design View. I am in here and then on the Format tab, turn off the navigation buttons. Now what this does is it does not allow changes. Yes, it does not allow the user to scroll through the customer. So if they want to go to a different customer, they can go to the customer list and pick someone from that. If they go to orders, they can't come back here and scroll. They could open up another customer here.

There are things you could do. You could make this form modal, which means that they can't go behind it. I have a modal form. I do not have a separate video on modal forms coming up. I cover this in my beginner classes though. If you go to other and change modal to yes, that means they cannot go behind this form. See how it's now modal? You can't go behind that form. You can open up another one on top of it, but you can't go behind this form until you close it. So if you open up that form, notice how it will collapse the navigation pane. I usually work with this closed or hidden.

If you open up a customer now, this is modal. You can't go pick another customer. If I open up orders and if I open up contacts, I can work with these because they're on top of this form technically, but if I close customers now, those shut down. See how that all works? So use a modal form and you can turn off the scroll bars and stuff down here too so it doesn't look like that big gray bar there.

Again, all formatting tips I cover in my beginner lessons. You can't go to a different customer now. If you open up orders, you're guaranteed that that's the orders for this customer. See how that works?

So that's it. That's how you can use one line of VB code to shut down another form, to close another open form.

In the extended cut, I will show you how to loop through all of the forms in the database and shut them all down in case you want to. One of my other members, Adam, asked that question. He said, "Is there a way to loop through all of the forms in the database? Shut them all down." Yes. I'll show you how in the extended cut.

Silver members and up get access to all of my extended cut videos and gold members can download the templates and access the code vault.

How do you become a member? Click the join button below the video. After you click the join button, you'll see a list of all the different types of membership levels that are available. Silver members and up will get access to all of the extended cut TechHelp videos, live video and chat sessions, and more. Gold members get access to a download folder containing all the sample databases that I build in my TechHelp videos, plus my code vault where I keep tons of different functions that I use. Platinum members get all the previous perks plus access to my full beginner courses and some of my expert courses. These are the full-length courses found on my website, and not just for Access. I also teach Word, Excel, Visual Basic, ASP, and lots more. But do not worry, these free TechHelp videos are going to keep coming. As long as you keep watching them, I'll keep making more.

If you liked this video, please give me a thumbs up and feel free to post any comments that you have. I do read them all. Make sure you subscribe to my channel, which is completely free, and click the bell icon and select all to receive notifications when new videos are posted.

Click on the Show More link below the video to find additional resources and links. You'll see a list of other videos, additional information related to the current topic, free lessons, and lots more.

YouTube no longer sends out email notifications when new videos are posted, so if you'd like to get an email every time I post a new video, click on the link to join my mailing list.

If you have not yet tried my free Access Level 1 course, check it out now. It covers all the basics of building databases with Access. It's over three hours long. You can find it on my website or on my YouTube channel. If you like Level 1, Level 2 is just $1. And it's also free for all members of my YouTube channel at any level.

Want to have your question answered in a video just like this one? Visit my TechHelp page and you can send me your question there.

Click here to watch my free Access Beginner Level 1 course, more of my TechHelp videos, or to subscribe to my channel.

Thanks for watching this video from AccessLearningZone.com.
Quiz Q1. What is the primary purpose of the DoCmd.Close VBA command demonstrated in the video?
A. To close a report in Access
B. To close an open form using VBA code
C. To open a new customer record
D. To save changes to a table

Q2. According to the video, which form event should you use to close related forms when the main customer form is closed?
A. On Load
B. On Current
C. On Close
D. On Open

Q3. Why might someone prefer to keep related forms as separate forms instead of subforms?
A. Separate forms can be resized and moved independently
B. Separate forms require no VBA coding
C. Subforms are always hidden in Access
D. Separate forms load faster

Q4. What is the correct syntax for closing a form called "ContactF" and saving any design changes using VBA?
A. DoCmd.Close acForm, "ContactF", acSaveYes
B. CloseForm "ContactF"
C. DoCmd.Exit acForm, "ContactF"
D. DoCmd.Delete "ContactF", acSaveYes

Q5. What option did the instructor recommend setting for saving design changes when closing forms for end users?
A. acSaveNo
B. acSavePrompt
C. acSaveYes
D. acDesignOnly

Q6. Why is acSaveYes acceptable for end users even if they cannot make design changes?
A. End users cannot save records
B. End users cannot modify the design in distributed databases
C. acSaveYes only saves table data
D. acSaveYes prevents accidental deletion

Q7. How can you prevent users from changing records while forms are open, as shown in the video?
A. Set the form to acReadOnly
B. Remove all navigation buttons in the Format tab
C. Lock all controls
D. Remove all fields from the form

Q8. What is a modal form in Access?
A. A form that prevents users from opening any other application
B. A form that floats above all other objects and cannot be moved
C. A form that must be closed before users can work with other forms in the database
D. A form that automatically updates all records

Q9. What happens if you open related forms like Orders and Contacts and then close the Customer form, after following the tutorial instructions?
A. Only the Customer form closes
B. The Orders and Contacts forms stay open
C. All related forms close automatically
D. The database closes completely

Q10. Where should you click in the form's property sheet to add VBA code to the On Close event?
A. The down arrow on the On Close event
B. The ellipsis (dot dot dot) button next to the On Close event
C. The Save button
D. The Data tab

Q11. What does the extended cut of the video promise to show?
A. How to create a new table
B. How to loop through all open forms and close them using VBA
C. How to import Excel data
D. How to design navigation forms

Q12. Which design trick was shown to prevent users from navigating to a different customer within the Customer form?
A. Remove scroll bars
B. Turn off the navigation buttons in the Format tab
C. Set form background color to gray
D. Lock the form header

Q13. Why is it necessary to use VBA code to link the closing of multiple forms, according to the video?
A. Access has built-in settings for this
B. There is no built-in way to automatically link closures of separate forms
C. Forms always close together by default
D. Macros can perform this task without VBA

Q14. In which editor does the instructor demonstrate adding the closing code for forms?
A. SQL Editor
B. Table Design View
C. VBA Editor (Code Builder)
D. Query Design View

Q15. What membership benefit is available to Gold members according to the video?
A. Only access to comments
B. Download folder with TechHelp sample databases and access to the code vault
C. The ability to edit Richard's website
D. Free Access Level 2 course only

Answers: 1-B; 2-C; 3-A; 4-A; 5-C; 6-B; 7-B; 8-C; 9-C; 10-B; 11-B; 12-B; 13-B; 14-C; 15-B

DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks.
Summary Today's video from Access Learning Zone covers how to automatically close related forms in Microsoft Access whenever you close a parent form, using VBA. I'm Richard Rost, your instructor, and I'll be walking you through this useful technique that was prompted by a question from one of my students.

Claudia, one of my platinum members, explained that she keeps several customer-related forms open in her Access database, like contacts, orders, and service calls. Each is its own separate form, which allows her to move and resize them independently. The challenge she faced was that closing the main customer form did not close these related forms, so she had to shut each one manually when she finished with a customer. She wanted to know if there is a way to have all the related forms close automatically when the customer form is closed.

Unless you nest your forms as subforms inside a main form, there is no built-in feature to tightly link separate forms that way. However, with a single line of VBA code, you can easily accomplish this task. I'll demonstrate exactly how this works and show you how to put that code in the right place.

First, if you're new to VBA in Access, I recommend reviewing my introductory video on VBA. It's short and will give you all the basics you need. Still, I'll guide you through the steps here.

Suppose you're working in your customer form and you have other forms open, such as orders and contacts. If you want both of those forms to close automatically when you close the customer form, you will need to use the On Close event of the customer form. To set this up, enter Design View for your customer form, open the property sheet, and go to the Events tab. Find the On Close event and choose to build some code there. This brings you into the VBA editor, right inside the form's Close event handler.

Now, the code you need is one simple command that closes another open form. With this command, you can specify which form you want to close, typically by its name in your database. You also get options to specify whether to save any design changes to the form as it is being closed. I generally opt for saving design changes by default, just in case I forget to save something I'm working on. For regular users, this is not a concern since they cannot alter the design of the forms.

Repeat this process for every form you want closed alongside your customer form. For instance, if you also want the orders form to close, just add another line for the orders form following the same pattern.

Once the event has been set up, test it out. Open your customer form and the related forms, then close the customer form. You'll see that all the specified related forms close as well. The whole solution only requires a single line of code for each related form, and it hinges on placing that code in the correct event for your parent form.

This process makes use of different events in Access forms. The On Close event runs when the form is closed. There are many other events, each corresponding to different activities within the form, like moving from record to record, opening the form, or loading data. These allow you to perform tasks automatically as users interact with your forms, and I discuss these events in greater detail in my other classes.

Keep in mind, there are some things to consider with this setup. For example, if you open the orders form and then switch to a different customer, the orders form will still be showing the original customer's data. You could use the On Current event to refresh or reopen related forms for the selected customer, which is a bit more advanced and covered in my other lessons. You might also want to limit users from switching records by disabling navigation buttons or making a form modal, which means users cannot interact with other forms behind it until it is closed.

Setting the customer form as modal ensures the user cannot click behind it and open a different customer or make accidental changes. You can also hide navigation buttons and format the forms to create a more seamless experience, all of which are discussed in my beginner-level lessons.

To summarize, by adding a single line of VBA code to the On Close event of your main form, you can automatically close any related forms, making database management much smoother for yourself and your users.

Also, in today's Extended Cut, I will demonstrate how to loop through all of the open forms in your database and close them with VBA, which is useful if you want to automatically close every form when certain actions occur.

If you're interested in accessing extended cut lessons, sample databases, or more advanced content, you can join as a member on my website. Each membership level comes with its own set of benefits, including extended lessons, downloads, and access to the code vault or full courses for higher levels.

For more resources, answers to questions, or to submit your own, visit my website. You can also find my comprehensive free Access Level 1 course, which you can start right away. If you want more, higher levels are available at a low cost or included with membership.

A full video tutorial with step-by-step instructions on everything discussed here can be found on my website at the link below.

Live long and prosper, my friends.
Topic List Using DoCmd.Close to close forms in Access with VBA

Setting up the On Close event for a form

Accessing form properties in Design View

Adding VBA code using the Code Builder

Closing related forms when the main form closes

Passing form names to DoCmd.Close

Choosing the acSaveYes option in DoCmd.Close

Disabling navigation buttons on a form

Setting a form as modal to prevent background access

Testing the closing of multiple related forms
 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/9/2026 2:42:51 PM. PLT: 2s
Keywords: TechHelp Access onclose, on close, on close event, close form, closeform, close all open forms, loop through forms, loop through all forms, close all forms  PermaLink  Close Form in Microsoft Access