Copyfile of current project that works in shared m

2019-07-08 02:31发布

问题:

The following is a greatly stripped-down version of some Access 2013 code which simply makes a copy of the current project under a new name.

It works only if the file is open in shared mode. If open in exclusive mode, this generates a "Permission denied" error.

Private Sub TestCopy()

    Dim sSourceFile, sSourcePath, sTargetFile, sTargetPath As String
    Dim AccessObj As Object

    sSourceFile = CurrentProject.Name
    sSourcePath = CurrentProject.Path
    sTargetFile = "TestCopy.accdb"
    sTargetPath = CurrentProject.Path

    Set AccessObj = CreateObject("Scripting.FileSystemObject")
    AccessObj.CopyFile sSourcePath & "\" & sSourceFile, sTargetPath & "\" & sTargetFile, True
    Set AccessObj = Nothing

End Sub

I'm surprised my research doesn't explain this. Is there another file copying method I can use within a database open in exclusive mode? Or do I need a method that runs outside the database?