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.

Recommended Answers

All 5 Replies

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

Why not use an MSDOS .bat file it's easier !

how? can you teach me? please

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.