473,408 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Closing all open objects

Hi everyone,

I am using Access 2010. I have a button on my main form that runs data checks for the user after they import their data. It opens up a mixture of queries, forms and reports.

I need a way to close everything that is open, except the main form. I found code on this site that I tried but I couldn't get to work. I found code on another site that works partially. The code successfully closes all of the open queries and some reports and some forms. But it leaves open about 3 reports and 3 forms that would have to be manually closed.

Am I missing something with the code?

I realize it also closes any open tables as well, which I left in the code in case at some point I add tables to the data checks in the future.

Thanks in advance,
Rhonda
Expand|Select|Wrap|Line Numbers
  1. Dim tbl As TableDef
  2. Dim qry As QueryDef
  3. Dim rpt As Report
  4. Dim frm As Form
  5.  
  6.   For Each tbl In CurrentDb.TableDefs
  7.     DoCmd.Close acTable, tbl.Name
  8.   Next tbl
  9.   For Each qry In CurrentDb.QueryDefs
  10.     DoCmd.Close acQuery, qry.Name
  11.   Next qry
  12.   For Each rpt In Application.Reports
  13.     DoCmd.Close acReport, rpt.Name
  14.   Next rpt
  15.   For Each frm In Application.Forms
  16.     If frm.Name <> "frmLevel1Switchboard" Then
  17.       DoCmd.Close acForm, frm.Name
  18.     End If
  19.   Next frm
  20.  
Feb 25 '16 #1

✓ answered by Rmoeller

I am not sure how to to remove a question once it is answered, but I found another topic on this site that seems to have answered my question with the code I couldn't get to work. So thank you all, its working now!

https://bytes.com/topic/access/answe...l-open-objects

1 5425
I am not sure how to to remove a question once it is answered, but I found another topic on this site that seems to have answered my question with the code I couldn't get to work. So thank you all, its working now!

https://bytes.com/topic/access/answe...l-open-objects
Feb 25 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dustin lee | last post by:
Over the years I've gotten out of the habit of explicitly closing file objects (whether for reading or writing) since the right thing always seems to happen auto-magically (e.g. files get written...
0
by: ajaykrishna | last post by:
Hi Could any one tell me what is the latest version of System.Data.OracleClient? Currently I'm using version 1.0.1012.0 in my project which is giving problem of not closing connection eventough...
1
by: csharpbeginner | last post by:
My requirement is a certain database connection should be closed only when the object is unloaded from memory. Is the class destructor a good place to close open database connections? Thanks in...
1
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
2
by: Lauren Wilson | last post by:
Hi folks, I believe I have seen this in this group in the past but my search comes up with nothing so far. I want to prevent our Access application from closing without some kind of...
2
by: News East | last post by:
Currently I must manually complete the following commands to set a new value for the "open objects" and "open indexes". I need a way script this process in a batch file. COMMANDS RAN: This is...
15
by: Sandra-24 | last post by:
I was reading over some python code recently, and I saw something like this: contents = open(file).read() And of course you can also do: open(file, "w").write(obj) Why do they no close...
7
by: billelev | last post by:
Does anyone know if it is possible to close all objects in a database (tables, forms, queries etc.) using VBA code? I have not been able to find anything online to help me so far... My motivation...
2
by: 47david | last post by:
Hi All Question re MS Access 2002 for Win XP new to this forum but have been following as a 'viewer' for some occasional help now have one I cant find any answers to I want to be able to...
6
by: SgtTurbo | last post by:
I would like to Close All Open Objects (Forms, Reports, Tables, Queries...) with a custom code. A quick internet search found an old thread from 2007 on this forum...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.