472,139 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 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 5396
NeoPa
32,497 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,497 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,497 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,497 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

Post your reply

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

Similar topics

3 posts views Thread by ucasesoftware | last post: by
1 post views Thread by teser3 | last post: by
reply views Thread by leo001 | last post: by

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.