Share via

Automatically Backup Database

Patrick Snyder 5 Reputation points
2026-02-24T14:00:46.2466667+00:00

I've watched several videos and either there is not enough information or it requires ActiveX and because I am on a server at work, I guess it's not allowed, I don't know...

I would like the database to automatically backup whenever the user clicks the exit button or close the program. I don't want a new file each time the database is closed, I'd like the previous file to be overwritten.

Help.

Microsoft 365 and Office | Access | Other | Windows
0 comments No comments

2 answers

Sort by: Most helpful
  1. George Hepworth 22,855 Reputation points Volunteer Moderator
    2026-02-24T14:24:09.6633333+00:00

    You can create code to do this. It's a great idea. One can never have too many backups. In fact, I rather think you should create incremental backups, not overwrite the previous backup. Why? If something goes wrong, there's a good chance the backup can also be corrupted. You want to be able to go back several generations, if needed.

    You can use the Windows Task Scheduler to make backups of any files or folders, and that is a reasonable alternative as well.

    Depending on how you are using Access, you may be able to handle the "backup on quit" task in a straightforward way. If you are talking about development sessions, it's a bit trickier than if you mean that you want users to be create backups when they quit.

    Note that, in a properly designed Access database, the interface objects are split into a separate accdb from the tables containing data. Usually, in a working production situation, backing up the data is the higher priority. In development, it's probably a higher priority to keep a version history of your front end, interface, accdb.

    I recommend a Version Control tool like https://github.com/joyfullservice for development. There are other options, including https://ivercy.com/

    These tools allow you to keep track of your work in developing the database.

    To get to a more specific consideration, it depends, in part, on whether you do mean development or production. In a production environment, where there can be multiple users making changes to the data in a shared back end, creating backups on close is not a good idea as it could lead to data loss if the back up interrupts another user's save of data.

    And, unless you are simply referring to your own development, I think a disciplined use of a VCS is a better choice than simply doing a backup on close. That said, the way to do that could be to write a procedure to save the accdb as a copy and put that procedure in the close event of a hidden form. Open that form when the accdb starts and leave it hidden. When the accdb closes, it will close that form, triggering its backup code.

    I guess we could discuss other aspects of the situation and focus on one more relevant tasks.

    Was this answer helpful?


  2. AI answer

    2026-02-24T14:00:56.1+00:00

    To automatically back up your Access database when the user exits the program, you can use the QuitAccess macro action. This action allows you to specify what happens to unsaved objects when quitting Access, and you can incorporate a backup operation before the exit command.

    Here’s a general approach you can follow:

    1. Create a Macro: In Access, create a new macro that first performs the backup operation and then calls the QuitAccess action.
    2. Backup Logic: Use a VBA function or a macro action to copy the database file to a designated backup location. You can use the CopyDatabaseFile action to overwrite the existing backup file each time the macro runs.
    3. Set the Exit Button: Assign this macro to the exit button in your Access application so that when the user clicks it, the backup is created, and then Access closes.

    Example Steps:

    • Use the CopyDatabaseFile action to specify the destination file name and set the Overwrite Existing File option to Yes.
    • Use the QuitAccess action to exit Access after the backup is complete.

    This way, every time the user exits the application, the current database will be backed up, and the previous backup file will be overwritten.

    Make sure that your database is trusted to allow these actions to run without restrictions.

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.