I have a backup procedure that is giving me a "Permission Denied" on my own profile. Can anyone spot an error in my code?
I've been over this and over it again. I haven't found a reason online that fits the situation. Any help would be greatly appreciated.
Code:
Public Function BackupFE()
On Error GoTo BackupFE_Err
Dim SourceFile As String, DestinationFile As String
Dim aFSO As Variant
Dim Path As String, Name As String
Path = CurrentProject.Path
Name = CurrentProject.Name
SourceFile = Environ("USERPROFILE") & "\Documents\" & _
"Invoices\InvoicesFE.accdb"
DestinationFile = Environ("USERPROFILE") & "\Documents\" & _
"Invoices\Backups\" & "InvoicesFE" & "_Backup" & "_" & _
Year(Now) & "-" & Month(Now) & "-" & Day(Now) & "_" & _
Hour(Now) & "-" & Minute(Now) & ".accdb"
'this removes a file created at the same time.
If Dir(DestinationFile) <> "" Then
Kill DestinationFile
End If
'this creates a backup into destination path
If Dir(DestinationFile) = "" Then
Set aFSO = CreateObject("Scripting.FileSystemObject")
aFSO.CopyFile SourceFile, DestinationFile, True
MsgBox "A database backup has been stored under " & DestinationFile
End If
BackupFE_Exit:
Exit Function
BackupFE_Err:
ErrMsg ("BackupFE")
Resume BackupFE_Exit
End Function
Last edited: