473,408 Members | 1,746 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.

How to close a Front End database from another one

759 512MB
Hello !

I have more than one Front End databases based on the same Back End database.

I know (but I think is not necessary) how to check from one of my Front End database if another one is running.
I wish to close, using VBA, all Front End databases except the current one.

Can you help me ?

Thank you !
Dec 20 '11 #1
6 5611
NeoPa
32,556 Expert Mod 16PB
Are you asking how to exit all copies of Access on the same PC other than the one just opened into this particular database, or is this more complicated than that?
Dec 21 '11 #2
Mihail
759 512MB
Thank you for reply, NeoPa.

You know very well this thread:
http://bytes.com/topic/access/answer...me#post3693605

The routine to relink tables work, for each FE, even if that FE is open. But the forms are not refreshed (and is not possible to do that because the data are changed when I switch to different BE).
So I wish to automatically close all that FEs in order to force the user to reopen it (and see new data).

One of the approach can be to prompt the user to manually close the FEs before run code to relink the tables. But I think that is more elegant to inform the user that the program will close other FEs and prompt he to allow (or not) this task. If the user do not allow that, the program will not relink tables.

It is strongly necessary that all my FEs to point, any time, to the same BE.

And NO.
I don't wish to exit from all copies of Access. Only to close specified instances: my FEs.
Dec 21 '11 #3
NeoPa
32,556 Expert Mod 16PB
In that case I'd take the approach of connecting to each open Application of Access and checking if it has an open database. If so, and the database is one from your list, then close it. I'm not sure how you can access multiple versions of Access I'm afraid. Once you have the Application object though, it's pretty straightforward to determine which database, if any, is open.
Dec 21 '11 #4
Mihail
759 512MB
This code check if a certain database is open:
Expand|Select|Wrap|Line Numbers
  1. Function IsDatabaseRunning(strDBName As String) As Boolean
  2. '   Function to check if a database is already running
  3. '   Accepts:
  4. '       The path and name of an Access database
  5. '   Returns:
  6. '       True if the database can't be opened (because it is already open)
  7. '       False if the database can be opened (because it is not already open)
  8.     On Error GoTo E_Handle
  9.     IsDatabaseRunning = True
  10.     Dim db As Database
  11.     Set db = DBEngine(0).OpenDatabase(strDBName, True)
  12.     IsDatabaseRunning = False
  13. fExit:
  14.     On Error Resume Next
  15.     db.Close
  16.     Set db = Nothing
  17.     Exit Function
  18. E_Handle:
  19.     Select Case Err.Number
  20.         Case 3704 ' Database already opened
  21.         Case Else
  22.             MsgBox "E_Handle  " & Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
  23.     End Select
  24.     Resume fExit
  25. End Function
So I know if one of my FE is open.
But no way to say to Access: Close that FE !

As far as I know the Application object can be used only for that instance of Access that running at a certain time (the Active one).
Hope I am wrong. Or to be another way to do the task.
Dec 21 '11 #5
NeoPa
32,556 Expert Mod 16PB
I've not done exactly this before, but if you can determine the names of the open databases then you should see if you can find a way of getting an Access.Application object for that particular Access session using Application Automation.
Dec 21 '11 #6
NeoPa
32,556 Expert Mod 16PB
FYI: I opened another database when I already had my Bytes.Mdb database open, and ran this code which worked perfectly as expected :
Expand|Select|Wrap|Line Numbers
  1. Public Sub TestCtrl()
  2.     Dim appBytes As Application
  3.  
  4.     Set appBytes = GetObject("H:\MyPath\Access\Bytes.Mdb", "Access.Application")
  5.     Debug.Print appBytes.CurrentDb.Name
  6. End Sub
The resultant string was :
Expand|Select|Wrap|Line Numbers
  1. H:\MyPath\Access\Bytes.Mdb
That should be enough to work with. The concept is proven.
Dec 21 '11 #7

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

Similar topics

3
by: Gary | last post by:
Hi, I have my main form1 and I want to close it and then show form2, in VB6 I used the following code... unload me form2.show in VB.net I got this far
3
by: ucasesoftware | last post by:
My update application have to close my software before xcopy... How can i do this ? thx a lot for help
8
by: bevanward | last post by:
Hi all I have a large data set of points situated in 3d space. I have a simple primary key and an x, y and z value. What I would like is an efficient method for finding the group of points...
15
by: Andyza | last post by:
I'm looking at another developers code and I'm now confused about the correct way to close a database connection and destroy the object. I would normally do it this way: Set conn =...
1
by: teser3 | last post by:
I have been using something similiar to below for inserting data into Oracle 9i using PHP but forgot to use the OCILogoff() method to logoff and was wondering what issues might occur with the...
9
by: Peter Webb | last post by:
I want to animate one object moving in front of another. I cannot re-render the background as the object moves, as it would be extremely time consuming. This is what I would like to do. I draw...
1
by: make me rain | last post by:
how to do this please. in vb6 i want to just close an access database so as to compact and backup. sub close database() dim dbs as database set dbs = "c:\howto-close_thisMDB.mdb" dbs.close end...
2
by: Dave Smith | last post by:
I have one database that on our server that 5 people login to. Sometimes throughout the month I need then to logout so I can add, update ect. Is there a simple code or way I can log everyone...
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.