How to shutdown all running Access when you need to do some changes. This is just a summary from Microsoft Docs. The steps are:
Create empty text file
- This file will be the
key
. - Name the file to anything like
checkfile.txt
Split DBMS
- You need
frontend
(FE) andbackend
(BE). - You can either create it separately and link the BE to FE later or split them.
Create linked form
- While in FE, create a form based on one of the linked tables from BE.
- Save the form and name it eg.
frm_Table1
.
Create empty form
- Create an empty from and name it eg.
frm_ShutDown
. - Go to form settings and under Hendelse property (sorry I don’t know what it’s called in english version) specify 60000 milliseconds (1 minute) or any numbers.
- While in
Design
options, selectView Code
in theTools
group. Then you can paste the VB code below with changes to the form names accordingly.
Option Explicit
Dim boolCountDown As Boolean
Dim intCountDownMinutes As Integer
Private Sub Form_Open(Cancel As Integer)
' Set Count Down variable to false
' on the initial opening of the form.
boolCountDown = False
End Sub
Private Sub Form_Timer()
On Error GoTo Err_Form_Timer
Dim strFileName As String
strFileName = Dir("c:\MyData\chkfile.ozx")
If boolCountDown = False Then
' Do nothing unless the check file is missing.
If strFileName <> "chkfile.ozx" Then
' The check file is not found so
' set the count down variable to true and
' number of minutes until this session
' of Access will be shut down.
boolCountDown = True
intCountDownMinutes = 2
End If
Else
' Count down variable is true so warn
' the user that the application will be shut down
' in X number of minutes. The number of minutes
' will be 1 less than the initial value of the
' intCountDownMinutes variable because the form timer
' event is set to fire every 60 seconds
intCountDownMinutes = intCountDownMinutes - 1
DoCmd.OpenForm "frmAppShutDownWarn"
Forms!frmAppShutDownWarn!txtWarning = "This application will be shut down in approximately " & intCountDownMinutes & " minute(s). Please save all work."
If intCountDownMinutes < 1 Then
' Shut down Access if the countdown is zero,
' saving all work by default.
Application.Quit acQuitSaveAll
End If
End If
Exit_Form_Timer:
Exit Sub
Err_Form_Timer:
Resume Next
End Sub
Create form to give warning
- Create an empty form and called it
frm_ShutDownWarn
. - While in the
Design
mode, addtext box
from options and put in the form. - Select the created text box and open
property
. - Open option for
Other
and inName
section writetxtWarning
as specified in the Visual Basic code above.
Create macro to execute commands
- Create a macro with
autoexec
to open these tables when launching the database. - Go to option
Create
and chooseMacro
. - Select an action with
Open form
and choose the form to open. Here it will befrm_ShutDown
. - Select
hiden
underWindow
options. - Save the macro as
autoexec
. This will run this macro when database is launched.
Shutdown
- To shutdown all open Access database, you just need to change the name of the
file
checkfile.txt
to something else eg.checkfile.bla
and save it. - The database will keep on checking this file every 1 minute (as specified with TimeInterval) and if the file is not found ie. the name has changed, then it will give warning and the database will be shutdown after 2 minutes (specified in VB code).