473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to use VBA code to close all open objects (forms, tables etc.)?

119 New Member
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 for doing this is the following:

I have two databases, call them A and B.

- Database A is linked to a table in database B.
- Database B is updated automatically using Windows Scheduler, on the hour.
- If an object in Database A with a dependency on the linked table in B is open when Database B is opened, Database B will return an error. I cannot have this.
- If all dependent objects in Database A are closed when B opens, there is no problem.
- I would like to automate the closure of Database A objects, to occur before Database B opens via Windows Scheduler. I would be able to do this via VBA code, if only I knew how!

Any help would be greatly appreciated.
Mar 9 '07 #1
7 35068
billelev
119 New Member
Just to elaborate a bit further...

I can see that
Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close
might be of use, but this requires each object to be explicitly named. I really need to find a way of closing all open objects, regardless of their names (i.e. I won't know which objects are open).
Mar 9 '07 #2
ADezii
8,834 Recognized Expert Expert
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 for doing this is the following:

I have two databases, call them A and B.

- Database A is linked to a table in database B.
- Database B is updated automatically using Windows Scheduler, on the hour.
- If an object in Database A with a dependency on the linked table in B is open when Database B is opened, Database B will return an error. I cannot have this.
- If all dependent objects in Database A are closed when B opens, there is no problem.
- I would like to automate the closure of Database A objects, to occur before Database B opens via Windows Scheduler. I would be able to do this via VBA code, if only I knew how!

Any help would be greatly appreciated.
There is a way to systematically check and see if any Access Objects are Open (Forms, Reports, Queries, etc,) and then to close them. This is fairly easy especially in the higher Versions of Access. Let me know if you are still interested and I'll work on the code.
Mar 9 '07 #3
billelev
119 New Member
If you don't mind, that would be very helpful. I'm running Access 2003 if that helps.
Mar 9 '07 #4
ADezii
8,834 Recognized Expert Expert
If you don't mind, that would be very helpful. I'm running Access 2003 if that helps.
This code should work very well for you:
Expand|Select|Wrap|Line Numbers
  1. Dim aob As AccessObject
  2. With CurrentData
  3.    ' "Tables"
  4.    For Each aob In .AllTables
  5.        If aob.IsLoaded Then
  6.            DoCmd.Close acTable, aob.Name, acSaveYes
  7.        End If
  8.    Next aob
  9.  
  10.    ' "Queries"
  11.    For Each aob In .AllQueries
  12.        If aob.IsLoaded Then
  13.            DoCmd.Close acQuery, aob.Name, acSaveYes
  14.        End If
  15.    Next aob
  16. End With
  17.  
  18.  
  19. With CurrentProject
  20.    ' "Forms"
  21.    For Each aob In .AllForms
  22.        If aob.IsLoaded Then
  23.            DoCmd.Close acForm, aob.Name, acSaveYes
  24.        End If
  25.    Next aob
  26.  
  27.    ' "Reports"
  28.    For Each aob In .AllReports
  29.        If aob.IsLoaded Then
  30.            DoCmd.Close acReport, aob.Name, acSaveYes
  31.        End If
  32.    Next aob
  33.  
  34.    ' "Pages"
  35.    For Each aob In .AllDataAccessPages
  36.        If aob.IsLoaded Then
  37.            DoCmd.Close acDataAccessPage, aob.Name, acSaveYes
  38.        End If
  39.    Next aob
  40.  
  41.    ' "Macros"
  42.    For Each aob In .AllMacros
  43.        If aob.IsLoaded Then
  44.            DoCmd.Close acMacro, aob.Name, acSaveYes
  45.        End If
  46.    Next aob
  47.  
  48.    ' "Modules"
  49.    For Each aob In .AllModules
  50.        If aob.IsLoaded Then
  51.            DoCmd.Close acModule, aob.Name, acSaveYes
  52.        End If
  53.    Next aob
  54. End With
Mar 10 '07 #5
NeoPa
32,578 Recognized Expert Moderator MVP
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 for doing this is the following:

I have two databases, call them A and B.

- Database A is linked to a table in database B.
- Database B is updated automatically using Windows Scheduler, on the hour.
- If an object in Database A with a dependency on the linked table in B is open when Database B is opened, Database B will return an error. I cannot have this.
- If all dependent objects in Database A are closed when B opens, there is no problem.
- I would like to automate the closure of Database A objects, to occur before Database B opens via Windows Scheduler. I would be able to do this via VBA code, if only I knew how!

Any help would be greatly appreciated.
If you have a scheduled task running on database B and this depends on no-one having any objects of database A (that refer to tables in database B) open, then you need to close database A objects from all sessions running anywhere and by anyone. This is not as simple as you seem to think. Closing them in your session would be pointless (There probably aren't any open in your session anyway.) as other sessions could be open. It is not possible programatically (and would be dangerous) to close all these objects in the other sessions.
Mar 10 '07 #6
billelev
119 New Member
That isn't actually an issue as there will probably only ever be one user, and all potential users sit opposite each other. Closing all of the objects automatically (even if only one user) is useful as it removes the need to remember to close the objects on the hour every hour.
Mar 13 '07 #7
NeoPa
32,578 Recognized Expert Moderator MVP
It is not possible programatically (and would be dangerous) to close all these objects in the other sessions.
I expect the fact that it can't be done may be a problem though.
Mar 13 '07 #8

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

Similar topics

0
3713
by: Bryan | last post by:
Can anyone give me some pointers please on where to look next in solving the problem I'm getting with running a Perl program (my first of any real complexity) from the command line in WindowsXP? Basically the program updates from a flat file an Access 2002 database consisting of just 4 tables (no queries, forms or reports as yet). It worked fine with a small amount of test data but gave the following error message after processing 60 or...
0
1689
by: markusp1982 | last post by:
Hello NG, I want to close open files which are locked by other users. I like to update an file. I dont want to delete the share file/folder. In the Computer Mangagement you can remove(cut) all open files.Or how can I block open files. Exists an method in .Net (WMI) or Windows Scripting Host in the code? thank you for the support an ideas.
2
5025
by: Bruno Rodrigues | last post by:
Hey, it's me again. Is there a way to, when closing a form, close also all forms opened inside this one? I'm not talking about MDI. Let's say I create and open three forms in Form1. When I close Form1, and he's not the main form of my app, I want to close all the three forms I opened. It would be nice to do that without a Form collection so I don't need to iterate throut it. Thanks.
5
1358
by: Steve Lloyd | last post by:
Hi, I have a multi form windows application but when i open new forms they do not load up "crisply", they open bit by bit as the items are drawn. What is the best way to open the form so that the entire form is drawn/shown at the same time. I hope this post makes sense, it is a bit hazey I'm affraid.
0
27052
by: nezoat | last post by:
Here is some working code to open the specified TCP port on the gateway nat device or firewall, and forward it to the calling machine. Great for p2p apps. The newsgroups are such a great resource and have helped me so much, I hope this helps others. Let me know if you find it useful! Lee Carlson Lee (at) Carlson (dot) net -----------------------------------
2
2101
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 nothing to script, these commands obtain the current values for open objects and open indexes. isql -Usa -Pmanager -SCOP1_DS execute sp_countmetadata "open objects"
7
12185
by: Mathew Butler | last post by:
I'm investigating an issue I have when pulling data back from MS access I'm retrieving all rows from a column in a table of 5000 rows - accessing a column of type "memo" ( can be 65353 character long) . I'm pulling the data back using ODBC. Details are: Microsoft Access Driver 4.00.6306.00 Jet 4.0 release level that is currently installed (Msjet40.dll ) "Microsoft Jet Engine Library" 4.0.9025.0 After 291 rows are retreived I am...
1
2350
by: bonnie.tangyn | last post by:
Hello all Would it be possible to store javascript document.forms.value to ASP session as global variable? If it is not possible, how can I pass the javascript document.forms.value to ASP/vbscript function? I need to pass the javascript value to ASP/vbscript function because I have to store the javascript value into database. I can't use Request.Form for getting field value. Because there is a
4
3169
D Giles
by: D Giles | last post by:
Have found many solutions on this forum to get to this point so finally registered. I have a form which should load 17 forms. Private Sub Form_Load() On Error GoTo Err_Form_Load DoCmd.Minimize DoCmd.OpenForm "Reminder Lease Expiry 6mth", acNormal DoCmd.OpenForm "Reminder Lease Expiry 2mth", acNormal DoCmd.OpenForm "Reminder Renewal 6mth", acNormal DoCmd.OpenForm "Reminder Renewal 2mth", acNormal
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10152
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.