:Permission Denied on my own profile

OBBurton

Registered User.
Local time
Today, 13:27
Joined
Dec 26, 2013
Messages
77
I have a backup procedure that is giving me a "Permission Denied" on my own profile. Can anyone spot an error in my code?
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
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.
 
Last edited:
Remember when I explained that FileSystemObject, VBA's FileCopy are doing this to protect your file for some reason? Well this is what is happening again. I did say that there are other "risky" ways of copying your file but you were adamant that wasn't the case.
 
a shot?

maybe access does not have inherent permission to read from this folder?

SourceFile = Environ("USERPROFILE") & "\Documents\" & _
"Invoices\InvoicesFE.accdb"

or maybe it won't copy while the file is in use?

--------
why not try the intrinsic "filecopy" command
you have filecopy, name and kill statements in access vba

aircode

filecopy sourcefile destinationfile
if dir(destinationfile)<>"" then kill sourcefile

or simply
name sourcefile destinationfile
(I think this will copy over different drives, like windows does)
 
FileCopy will do the same thing. OB needs Shell's Copy command.
 

Users who are viewing this thread

Back
Top Bottom