A few errors with backslashes in your code
a) there shouldn't be a backslash before T:\
b) there should be a backslash between file path and file name
Code:
Dim myFile, myBEPath, BackupFile, BackupPath As String
myBEPath = "T:\DMT\DB Backend"
myFile = "DMT Live_be" & ".accdb"
BackupPath = "T:\DMT\DB Backup"
BackupFile = "DMT Live_be" & ".accdb" & " " & Format(Now(), "dd-mm-yy")
FileCopy myPath & "\" & myFile, BackupPath & "\" & BackupFile
However you may find the following two functions more useful -they are similar to the functions I use
These backup the FE or BE database to a specified folder and show a message with the backup file name/location/size
In each case, the file is first copied to a temp file then compacted before copying the compacted file to the final location
1. Backup BE file
Code:
Public Function BackupBEDatabase()
On Error GoTo Err_Handler
'creates a copy of the backend database to the backups folder with date/time suffix
Dim fso As Object
Dim strOldPath As String, strNewPath As String, strTempPath As String, strFileSize As String
Dim newlength As Long
Dim STR_PASSWORD As String
'if your BE database is password protected, enter it below or state where it can be found
' STR_PASSWORD = "" 'enter password
' STR_PASSWORD = Nz(DLookup("ItemValue", "tblProgramSettings", "ItemName='Pwd'"), "") 'example for stored password
Set fso = CreateObject("Scripting.FileSystemObject")
strFilename = "UKAddressFinderBE.accdb" 'replace with your BE file
strFileType = Mid(strFilename, InStr(strFilename, ".")) 'e.g. .accdb
strOldPath = GetLinkedDBFolder & "\" & strFilename 'replace GetLinkedDBFolder with your BE folder
'replace GetBackupsFolder with your backups folder
strNewPath = GetBackupsFolder & "\BE\" & Left(strFilename, InStr(strFilename, ".") - 1) & "_" & Format(Now, "yyyymmddhhnnss") & strFileType
'set path for temp file
strTempPath = GetBackupsFolder & "\" & Left(strFilename, InStr(strFilename, ".") - 1) & "_TEMP" & strFileType
' Debug.Print strOldPath
' Debug.Print strTempPath
' Debug.Print strNewPath
If MsgBox("This procedure is used to make a backup copy of the back end database" & vbCrLf & _
"The backup will be saved to the Backups folder with date/time suffix" & vbCrLf & _
vbTab & "e.g. " & strNewPath & " " & vbCrLf & vbCrLf & _
"This can be used for recovery in case of problems " & vbCrLf & vbCrLf & _
"Create a backup now?", _
vbExclamation + vbYesNo, "Copy the Access BE database?") = vbNo Then
Exit Function
Else
'copy database to a temp file
fso.CopyFile strOldPath, strTempPath
Set fso = Nothing
'compact the temp file (with password)
DBEngine.CompactDatabase strTempPath, strNewPath, ";PWD=" & STR_PASSWORD & "", , ";PWD=" & STR_PASSWORD & ""
'OR compact the temp file code if no password
'DBEngine.CompactDatabase strTempPath, strNewPath
'delete the tempfile
Kill strTempPath
DoEvents
'get size of backup
newlength = FileLen(strNewPath) 'in bytes
'setup string to display file size
If FileLen(strNewPath) < 1024 Then 'less than 1KB
strFileSize = newlength & " bytes"
ElseIf FileLen(strNewPath) < 1024 ^ 2 Then 'less than 1MB
strFileSize = Round((newlength / 1024), 0) & " KB"
ElseIf newlength < 1024 ^ 3 Then 'less than 1GB
strFileSize = Round((newlength / 1024), 0) & " KB (" & Round((newlength / 1024 ^ 2), 1) & " MB)"
Else 'more than 1GB
strFileSize = Round((newlength / 1024), 0) & " KB (" & Round((newlength / 1024 ^ 3), 2) & " GB)"
End If
DoEvents
End If
MsgBox "The Access backend database has been successfully backed up. " & _
"The backup file is called " & vbCrLf & vbTab & strNewPath & vbCrLf & vbCrLf & _
"The file size is " & strFileSize, vbInformation, "Access BE Backup completed"
Exit_Handler:
Exit Function
Err_Handler:
Set fso = Nothing
If Err <> 0 Then
MsgBox "Error " & Err.Number & " in BackupBEDatabase procedure : " & _
Err.description, vbCritical, "Error copying database"
End If
Resume Exit_Handler
End Function
2. Backup FE file
Code:
Public Function BackupFEDatabase()
On Error GoTo Err_Handler
'creates a copy of the current db (frontend) to the backups folder with date/time suffix
Dim fso As Object
Dim strOldPath As String, strNewPath As String, strTempPath As String, strFileSize As String
Dim newlength As Long
Set fso = CreateObject("Scripting.FileSystemObject")
strFileType = Mid(CurrentDb.Name, InStr(CurrentDb.Name, ".")) 'e.g. .accdb
strFilename = Mid(CurrentDb.Name, InStrRev(CurrentDb.Name, "\") + 1)
strFilename = Left(strFilename, Len(strFilename) - Len(strFileType))
strOldPath = CurrentDb.Name
strTempPath = Left(CurrentDb.Name, InStr(CurrentDb.Name, ".") - 1) & "_TEMP" & Mid(CurrentDb.Name, InStr(CurrentDb.Name, "."))
strNewPath = GetBackupsFolder & "\FE\" & strFilename & "_" & Format(Now, "yyyymmddhhnnss") & strFileType
If MsgBox("This procedure is used to make a backup copy of the front end (FE) database." & vbCrLf & _
"The backup will be saved to the Backups folder with date/time suffix" & vbCrLf & vbTab & "e.g. " & strNewPath & vbCrLf & vbCrLf & _
"This can be used for recovery in case of problems " & vbCrLf & vbCrLf & _
"Create a backup now?", _
vbExclamation + vbYesNo, "Copy the Access FE database?") = vbNo Then
Exit Function
Else
'copy database to a temp file
fso.CopyFile strOldPath, strTempPath
Set fso = Nothing
strNewPath = GetBackupsFolder & "\FE\" & strFilename & "_" & Format(Now, "yyyymmddhhnnss") & strFileType
'Debug.Print strTempPath
'Debug.Print strNewPath
'compact the temp file
DBEngine.CompactDatabase strTempPath, strNewPath
'delete the tempfile
Kill strTempPath
DoEvents
'get size of backup
newlength = FileLen(strNewPath) 'in bytes
'setup string to display file size
If FileLen(strNewPath) < 1024 Then 'less than 1KB
strFileSize = newlength & " bytes"
ElseIf FileLen(strNewPath) < 1024 ^ 2 Then 'less than 1MB
strFileSize = Round((newlength / 1024), 0) & " KB"
ElseIf newlength < 1024 ^ 3 Then 'less than 1GB
strFileSize = Round((newlength / 1024), 0) & " KB (" & Round((newlength / 1024 ^ 2), 1) & " MB)"
Else 'more than 1GB
strFileSize = Round((newlength / 1024), 0) & " KB (" & Round((newlength / 1024 ^ 3), 2) & " GB)"
End If
DoEvents
End If
MsgBox "The Access FE database has been successfully backed up. " & _
"The backup file is called " & vbCrLf & vbTab & strNewPath & vbCrLf & vbCrLf & _
"The file size is " & strFileSize, vbInformation, "Access FE Backup completed"
Exit_Handler:
Exit Function
Err_Handler:
Set fso = Nothing
If Err <> 0 Then
MsgBox "Error " & Err.Number & " in BackupFEDatabase procedure : " & _
Err.description, vbCritical, "Error copying database"
End If
Resume Exit_Handler
End Function
Example message on completion: