Results 1 to 8 of 8
  1. #1
    shaztastic is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    14

    VBA to copy a folder and retain its security permissions

    I need to amend the following code so that when it copies the folder it retains all the permissions I think maybe xcopy will work but I don't know how to amend the code to make it work...would really appreciate any help...

    Code:
    Private Sub Command27_Click()
    'This example copy all files and subfolders from FromPath to ToPath.
    'Note: If ToPath already exist it will overwrite existing files in this folder
    'if ToPath not exist it will be made for you.
          
     Dim FSO As Object
     Dim FromPath As String
     Dim ToPath As String
     
      
     If IsNull(Me.Client) Then
     
        DoCmd.Close
     
     Exit Sub
     End If
     
     
         
     FromPath = "Q:\01-Estimating\1.1-Tender Files\_Tender File"   '<< Change this to final drive location sharon ***
     ToPath = "Q:\01-Estimating\1.1-Tender Files\" & (Text93)     '<< Change sharon ***
        'If you want to create a backup of your folder every time you run this macro
    'you can create a unique folder with a Date/Time stamp.
    'ToPath = "C:\Users\Ron\" & Format(Now, "yyyy-mm-dd h-mm-ss")
    If Right(FromPath, 1) = "\" Then
    FromPath = Left(FromPath, Len(FromPath) - 1)
    End If
    If Right(ToPath, 1) = "\" Then
    ToPath = Left(ToPath, Len(ToPath) - 1)
    End If
     Set FSO = CreateObject("scripting.filesystemobject")
    If FSO.FolderExists(FromPath) = False Then
    MsgBox FromPath & " doesn't exist"
    Exit Sub
    End If
    FSO.CopyFolder Source:=FromPath, Destination:=ToPath
    MsgBox "A Tender File has now been created for this project on  " & ToPath
    
       DoCmd.Close
       
       End Sub


  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    If they are both within the "1.1-Tender Files" folder, cant that folder have the security permissions already?

  3. #3
    shaztastic is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    14
    Quote Originally Posted by Homegrownandy View Post
    If they are both within the "1.1-Tender Files" folder, cant that folder have the security permissions already?
    I need to set different permissions on each subfolder within the 1.1-Tender File folder. I can do this by removing inherited permissions, however as soon as I copy it the newly created folder reverts back to having its parent folder inherited permissions.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Quote Originally Posted by shaztastic View Post
    I need to set different permissions on each subfolder within the 1.1-Tender File folder. I can do this by removing inherited permissions, however as soon as I copy it the newly created folder reverts back to having its parent folder inherited permissions.
    I think that is windows default behaviour, and can only be switched on/off at a folder level within windows.
    Because of that you would need to set the permissions after copying the folder/file.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    shaztastic is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    14
    You can use the Xcopy command with the /O/X/E/H/K switches to copy the files and retain the existing permissions that have been specifically applied to the file or files, however I'm just not sure how to apply it within my existing code......


    https://support.microsoft.com/fr-ca/...ts-permissions

  6. #6
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Robocopy will also allow you to do that, maybe you could simply shell out to either to achieve what you want.

    AFAIKS there are no switches or options in the FSO to do what you need.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    shaztastic is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    14
    That’s the bit I’m not sure about. How do I change the code I’ve got to do that?

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I did some searching and found some info:

    (read links in order)
    https://access-programmers.co.uk/for...d.php?t=215253
    https://www.techrepublic.com/article...-windows-acls/

    Found a couple of references that said Cacls is deprecated. (but if you open a DOS window and type HELP, you will still see the command... as well as ICACLS.)

    https://stackoverflow.com/questions/...ine-in-windows



    So you might be able to shell out to use th ICACLS command to control/set permissions..........


    Good luck....

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 03-09-2017, 04:08 PM
  2. Replies: 5
    Last Post: 11-17-2016, 04:28 PM
  3. Get folder permissions and put them in a table
    By etsoft in forum Programming
    Replies: 1
    Last Post: 08-25-2015, 07:15 AM
  4. Individual Security Level Permissions
    By jle0003 in forum Security
    Replies: 2
    Last Post: 08-13-2012, 01:38 PM
  5. No permissions after security was setup
    By postiekiddo in forum Security
    Replies: 3
    Last Post: 07-07-2011, 01:26 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums