Hallo guys, it is me again. I need help how to create a simple backup file by just copying a file to another folder.
Look at my code.

Private Sub mnuBackup_Click()
Dim SourceFile, DestinationFile As String
On Error GoTo FileCopyFailed

    SourceFile = "D:\MyWorks\data\facility.mdb"
    DestinationFile = "D:\MyWorks\backup\facility.mdb"
    FileCopy SourceFile, DestinationFile
    MsgBox "BACKUP FILE WAS SUCCESSFUL!", vbInformation
    Exit Sub

FileCopyFailed:
    MsgBox Err.Number & " " & Err.Description & " " & Err.Source
    Err.Clear
    Resume Next
End Sub

what am i going to do with this code. The error is the one is red color.

If you have the database open via your code or through the access application then you will recieve this error. You need to close all connections to the database prior to trying to copy it.

Good Luck

If you have the database open via your code or through the access application then you will recieve this error. You need to close all connections to the database prior to trying to copy it.

Good Luck

how am I going to do that?

how am I going to do that?

For each object you open (cn.open/rs.open) you need to close (rs.close/cn.close). So if you have a global/public connection and any global/public recordsets open, you close, copy, and then reopen if you want to continue on with your program.

Good Luck

This question has already been answered. Start a new discussion instead.