Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
a button forclose and open
John Yeung 
     
3 years ago
just for fun, I created a button with code
DoCmd.Close acForm, "frm_A", acSaveYes
DoCmd.OpenForm "frm_A"

I thought the form would close and not reopen again as the form has already closed, the second command could not be executed. But the form did close and open again . strange

anyone knows why?  
Juan C Rivera  @Reply  
             
3 years ago

your code worked correctly i am thinking it closed and open just to fast
Kevin Robertson  @Reply  
          
3 years ago
The code will run to the end of the Sub Routine unless you tell it to exit for whatever reason.
Gregory Clancey  @Reply  
    
3 years ago
Could it be that an "If" test with an "Exit Sub" is called for to re-open the Form only if it had been closed?
Kevin Robertson  @Reply  
          
3 years ago
Try this guys (changing FormName to the name of the form).

    DoCmd.Close
    MsgBox "The form has closed"

    DoCmd.OpenForm "FormName"
    MsgBox "The form has re-opened"


This will close the form then display the first message.
When you click the OK button the form will re-open and display the second message.

Add the following line between the two code blocks and the form won't re-open.

    If Not CurrentProject.AllForms("FormName").IsLoaded Then Exit Sub
Gregory Clancey  @Reply  
    
3 years ago
Thanks. This works perfectly for me and can be custom tailored to work in other circumstances as well!

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

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: 5/7/2026 3:47:42 AM. PLT: 0s