Am trying to BACKUP database in .bak format and when i compile it am getting

-2147221504
source file doesnt exist error

can anybody please HELP..

Thanks in advance

Am trying to back up MSaccess database using .bak file.. the that am using is below and it comes right at the place where i ve bolded the words and displays the source file doesnt exist error..

Private Sub BackUpDB()

Dim FSO As New FileSystemObject

Dim sDBfn As String
Dim sDBTmpfn As String

If FSO.FolderExists(App.Path & "/Backup") = False Then
FSO.CreateFolder App.Path & "/Backup"
End If

'set backup file path filename
sDBfn = App.Path & "/Backup/" & Format$(Date, "ddmmyyyy") & ".bak"
'set temporary file
sDBTmpfn = sDBfn & Now - DateValue(Now) & GetTickCount

If FSO.FileExists(sDBTmpfn) = True Then
FSO.DeleteFile sDBTmpfn
End If

'show ctl
progStat.Visible = True
lblCBK.Visible = True
DoEvents

'start backup
Set frmbackup.clsBKU = New clsHuffman
frmbackup.clsBKU.EncodeFile DBPathFileName, sDBTmpfn

'rename file
If FSO.FileExists(sDBfn) = True Then
FSO.DeleteFile sDBfn
End If
FSO.MoveFile sDBTmpfn, sDBfn

Set FSO = Nothing
progStat.Visible = False
lblCBK.Visible = False
End Sub

isn't sDBTmpfn incorrect, it should be the file name of the database you are trying to back up.

and the MoveFile should probably be a CopyFile

Chris i tried it aint workin.. Wat i should use in place of sdbtmpfn

the filename of the database you wish to backup, eg


FSO.CopyFile App.Path & "\MyDatabase.mdb", sDBfn

you need to need to ensure that the database is not open at the time. The easiest is to start your VB program in sub Main and backup there before any links to the database have been created.

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