Setting Permissions on a Folder in VBA

txgeekgirl

Registered User.
Local time
Today, 02:37
Joined
Jul 31, 2008
Messages
187
Below is the code I am using to make a directory folder. I do need to set the Share Name and Security Permissions in VBA. I found that little three lines at the bottom but it is bombing on SetAccess. I am guessing it's a VB command and not VBA crossover - does anyone know a command for this? :confused:

Code:
[B]Sub Create_E_Drive()
    Dim FName, LName, Target, FolderName As String
    Dim sUserName As String
    Dim sFolderName As String[/B]
[B]    
    Target = "\\File_Center\Folders\"
    FName = DLookup("NewStaff_F_Name", "NewStaffRequests", "ID = " & myRec)
    LName = DLookup("NewStaff_L_Name", "NewStaffRequests", "ID = " & myRec)
    FolderName = FName & LName
    
    'Make Directory
    If Dir(Target & FolderName, vbDirectory) = "" Then
        MkDir Target & FolderName
    Else
        MsgBox ("E:\ Exists - will check for shares and permissions.")
    End If
    
    sUserName = FName & " " & LName
    sFolderName = FolderName & "$"
    SetAccess sUserName, sFolderName, GENERIC_READ Or GENERIC_EXECUTE Or Delete Or GENERIC_WRITE Or GENERIC_ALL[/B]
[B]
End Sub[/B]
 
TX girl,

Is ''SETACCESS'' an application method in access? doesn't look familiar. If it's not, and you're not calling a function that you've dec'd somewhere else in your code, obviously it wouldn't work.

Where did you get ''SETACCESS'' from? Furthermore, are you sure vb can even do this? I would guess an API would be required. this is a windows function. and regarding your args, do you even have the constants (''GENERIC_EXECUTE'', etc..) dec'd?
 
Have you looked at the built-in command line function CACLS. Might work but you may need to write a bat file or script to run it.

Code:
CACLS filename [/T] [/E] [/C] [/G user:perm] [/R user [...]]
               [/P user:perm [...]] [/D user [...]]
   filename      Displays ACLs.
   /T            Changes ACLs of specified files in
                 the current directory and all subdirectories.
   /E            Edit ACL instead of replacing it.
   /C            Continue on access denied errors.
   /G user:perm  Grant specified user access rights.
                 Perm can be: R  Read
                              W  Write
                              C  Change (write)
                              F  Full control
   /R user       Revoke specified user's access rights (only valid with /E).
   /P user:perm  Replace specified user's access rights.
                 Perm can be: N  None
                              R  Read
                              W  Write
                              C  Change (write)
                              F  Full control
   /D user       Deny specified user access.
Wildcards can be used to specify more that one file in a command.
You can specify more than one user in a command.
Abbreviations:
   CI - Container Inherit.
        The ACE will be inherited by directories.
   OI - Object Inherit.
        The ACE will be inherited by files.
   IO - Inherit Only.
        The ACE does not apply to the current file/directory.
 
I was looking through online articles on how to set permissions via VBA and found this:

http://allapi.mentalis.org/apilist/9C3BBC69930313A7D25B3142EF2C084B.html

It's in VB and does have an expanded region and now that I have searched the code - I see the function defined way below - It's not going to be VBA compatible.

how do you know it's not compatible? There's very few vb6 code snippets out there that won't work in vba.

WHAT'S not compatible? What do you see? the difference between vba and vb6 (which is what your link is written in) is essentially the program's object structure, which has nothing to do with your purposes here.
 
The_Net_2.0 - You are correct. I pretty much cut and paste the code into my VBA code and it does run with little error. I think it's where to put all of the APIs in the code. You can't have them in a Sub and 3 are coming up with an error of being invalid. So I am playing and chopping.
 

Users who are viewing this thread

Back
Top Bottom