Can an Ms Access database create a backup of itself while it's open using vba?

Viewed 10449

Background: I have a process that links Quickbooks to Ms Access. If a button is pressed, some information will be queried from Quickbooks and then updates Ms Access. If the power goes out, or if the user forces Ms Access to close during the sync process, it can cause some of the information to be corrupted.

Goal: I want to have a button on a form that users can press and it'll save the current database to a predefined location with the date and time attached to the filename.

I keep reading how it's possible to backup other closed databases (using FileCopy), but you need a hacky-workaround solution to do it on an open database, which can lead to data corruption. I'm not entirely convinced since the user can use "Save As" at any time.

Is there a way to backup a currently open Ms Access database, or something that will fulfill my needs?

3 Answers

You can try using FileSystemObject like this:

    'strFrom = Application.CurrentProject.FullName
    'strTo = "C:\FolderName\NewFileName.accdb"

Public Sub copyFile(strFrom As String, strTo As String)
    Dim fso As FileSystemObject
    Set fso = New FileSystemObject

    fso.copyFile strFrom, strTo

    Set fso = Nothing

End Sub
Related