Public Function RunExternalDatabase()
Dim app As Access.Application, strPath As String, strLockPath As String
'Start a new Access application
Set app = New Access.Application
strPath = "YourFullFilepathHere.accdb" 'enter your full file path
strLockPath=Left(strPath, Len(strPath)-5) & "laccdb"
If Len(strLockPath) > 0 Then MsgBox "File is in use" 'this won't detect if opened exclusively as no lock file is created
'Open the remote database and (optionally) run a macro, then close the remote database
With app
'Syntax: .OpenCurrentDatabase(filepath, Exclusive, strPassword) - the last 2 items are optional
.OpenCurrentDatabase strPath ', False ', "password"
.Visible = True 'optional
' .DoCmd.RunMacro "mcrRefreshPersTable" 'run your macro (optional)
.CloseCurrentDatabase 'closes external database as that is current
End With
'Quit the spawned app
app.Quit acQuitSaveNone
Set app = Nothing
'Quit the current app - optional
'Application.Quit acQuitSaveNone
End Function
I don't want to open it. I just want to close it. It's completely different.It is easy enough to open an external database, do something & close it again....
The only real solution I can think of is to use 'kickout code' built into your other app to close it automatically after a period of inactivity
I don't want to open it. I just want to close it. It's completely different.
Even though I find a way to do it, showing the user a message to close another.accdb manually is much more practical(for my situation).
Where can I ask several questions about this forum and how it works, may some suggestions and a very strange thing that I just found out?
If the other DB is open from the current app, there is a collection in Workspaces called .Databases that you can examine using collection-handling methods. The .Path string for each open database should be visible. If you can see it this way, you can close it.
If the other DB is open from a different app then you might have issues doing this interactively. Windows Resource Manager can show you a list of open file handles but that is hard to read from an Access app. There is also the command-line utility called OpenFiles but you need to do some registry things first to enable this. If you do, you might be able to write a shell script or issue some SHELL commands.
If the putative file is on another system in your network, OpenFiles might still be useful but requires elevated privileges. At the very least, perhaps Operator privilege to even see such a list, or Admin to do more than just see it. And at that level, there are some sys admin tools you could look up.
I take a different approach.When users click on the desktop shortcut to my apps, they are actually launching a small 'starter app'. This checks for a newer version
You need to prompt them in their own fe as in "Update? y/n". If no, just quit their db (assuming you don't want them to work in an outdated version). If yes, call the code that over-writes their copy by passing the CurrentProject.Path to it then Quit. Now the over-write can occur because their db is closed and all they had to do was one click for "yes". The upgrading code should be able to re-launch their updgraded version based on the path you passed to it. Optionally, you can store a copy of their fe if it has user level tables with data that needs to be kept in case the upgrade fails. Then on successful startup after the upload, kill the backup version - or not.why I don't update it automatically.
It would be appreciated if you gave the correct explanation from the start.
It would have saved us all a lot of time!![]()
When users click on the desktop shortcut to my apps, they are actually launching a small 'starter app'. This checks for a newer version in an upgrade folder on the network as you are doing .
If users already have the latest version, the starter app closes & launches the main app
If a newer version is found, the required files are downloaded to the user's PC and then the main app is launched. As APIs are used this is VERY fast. The process can also be used to update the starter app itself if a newer version is available
I take a different approach.
Rather than a starter app, on open I perform a check on the version number stored in a local file in the FE and compare it with the version stored in the BE. Then start an 'upgrader app'.
Intra day checks could be implemented using code in a timer event in a hidden continuously open form on the FE.
Either way avoids the need to close FE's from the server.
FWIW my starter utility checks the version number against a small version.txt file in the upgrade folder.
It also checks the date modified on the app itself in that folder.
If the version number is higher or the network file is newer it copies across the files.
It also has provision to force an upgrade just in case anything ever goes wrong.
Thanks for additional info.
I can't trust a local file, specially a text file. These users are crazy and like to play tricks on me. If I leave a local file, they simply delete it or change its contents to something that their copy will never be upgraded.
Since I use SQL server as backend, I save the latest version number in a SystemOption table in SQL server. And I have a local table that keeps the current version of FE. I simply compare these two values.
I also have a table to keep track of changes with each version. And users can see a version history, if they go to their help tab in the ribbon.
I can't trust a local file, specially a text file. These users are crazy and like to play tricks on me. If I leave a local file, they simply delete it or change its contents to something that their copy will never be upgraded.
Since I use SQL server as backend, I save the latest version number in a SystemOption table in SQL server. And I have a local table that keeps the current version of FE. I simply compare these two values.