Code Samples for Businesses, Schools & Developers

First Published 23 Sept 2026



This article shows how the current database can be safely closed and restarted using code.
This can be useful if you use VBA to change an option which requires a restart to take effect e.g. change Office language or document display option.


CODE:

Public Sub RestartCurrentDatabase()
Dim strPath As String
Dim strAccessExe As String
Dim strCommand As String

' 1. If you want to ensure the current active record is saved before restarting:
' On Error Resume Next
' If Screen.ActiveForm.Dirty Then Screen.ActiveForm.Dirty = False
' On Error GoTo 0

' 2. Get current database full path
strPath = Application.CurrentProject.FullName

' 3. Dynamically retrieve the Access installation path using SysCmd
strAccessExe = SysCmd(acSysCmdAccessDir) & "MSACCESS.EXE"

' 4. Build shell execution string with a 1-second delay to release locks
strCommand = "cmd.exe /c timeout /t 1 /nobreak >nul & """ & strAccessExe & """ """ & strPath & """"

' 5. Spawn background shell process
Shell strCommand, vbHide

' 6. Quit current instance safely
Application.Quit acQuitSaveAll
End Sub


The code can be run from a form or a standard module. It can also be run from a macro provided it is changed to a function.

Many thanks to Xevi Batlle for suggesting this code.



Download

Click to download: Restart Access    (ACCDB file - approx 0.35 MB (zipped)

As is the case for all files downloaded from the internet, first unblock the downloaded file, unzip then save to a trusted location.
For more details, see my article: Unblock downloaded files by removing the Mark of the Web



Feedback

Please use the Email button in the contact form below to let me know whether you found this article useful or if you have any questions.

Please also consider making a donation towards the costs of maintaining this website. Thank you


Colin Riddington Mendip Data Systems Last Updated 23 Sept 2026




Return to Code Samples Page




Return to Top