Results 1 to 2 of 2
  1. #1
    JezPerth is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Apr 2013
    Posts
    5

    Setting Permissions via vba / dao

    I am having trouble matching the Permissions constants to the values of the Permissions property for containers and documents.
    (I need to do this so that I can assign Permissions via vba using DAO).
    The constants available (with values determined via Immediate window), according to the VBA Help, are:
    For tables container, and tables:
    dbSecCreate: 1
    dbSecReadDef: 4
    dbSecWriteDef: 65548
    dbSecRetrieveData: 20
    dbSecInsertData: 32
    dbSecReplaceData: 64
    dbSecDeleteData: 128
    For other containers (except Databases), and all other documents (forms, reports, scripts, etc):
    dbSecNoAccess (For container only; not applicable to docs): 0
    dbSecFullAccess: 1048575
    dbSecDelete: 65536
    dbSecReadSec: 131072
    dbSecWriteSec: 262144
    dbSecWriteOwner: 524288
    If I manually set some permissions and then read them via vba I get the following values, that I cannot duplicate with any combination of the above constants, which is why I'm wondering if I'm missing some constants.
    So does anyone know if there are other constants than those above? .. or can anyone shed any other light on this issue please?
    -----------------------------------------
    CONTAINERS
    Forms Container
    I manually assign only Open/Run to the container (ie to <New Forms> via the "User and Group Permissions" dialog).
    The Permissions value, read via vba, is 257.
    Reports Container
    I manually assign only Open/Run to the container (ie to <New Reports> via the "User and Group Permissions" dialog).
    The Permissions value, read via vba, is 257.
    Scripts Container
    I manually assign only Open/Run to the container (ie to <New Macros> via the "User and Group Permissions" dialog).
    The Permissions value, read via vba, is 9.
    -----------------------------------------
    DOCUMENTS
    Forms
    I assign only Open/Run to a test form.
    The Permissions value, read via vba, is 256 (prior to creating the Container defaults above .. and 257 after doing this).
    I assign only Open/Run, plus Read Design, to a test form.
    The Permissions value, read via vba, is 260.
    Reports
    I assign only Open/Run to a test report.
    The Permissions value, read via vba, is 257.
    I assign only Open/Run, plus Read Design, to a test report
    The Permissions value, read via vba, is 261.
    Macros (scripts)
    I assign only Open/Run to a test macro.
    The Permissions value, read via vba, is 8.
    -----------------------------------------
    Here is the code used to get the Permissions values via VBA:
    (pcGrpName is a parameter which contains the Group name).
    Set lDb = CurrentDb
    'Get current permissions for pcGrpName on containers:


    Set lCtr = lDb.Containers("Tables") 'Includes queries
    lCtr.UserName = pcGrpName
    lcMsg = "Tables Container: " & lCtr.Permissions
    Set lCtr = lDb.Containers("Forms")
    lCtr.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Forms Container: " & lCtr.Permissions
    Set lCtr = lDb.Containers("Reports")
    lCtr.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Reports Container: " & lCtr.Permissions
    Set lCtr = lDb.Containers("Scripts")
    lCtr.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Scripts Container: " & lCtr.Permissions
    'Get current permissions for pcGrpName on the test objects:
    'Tables:
    Set lDoc = lDb.Containers("Tables").Documents("aRd")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Local Table aRd: " & lDoc.Permissions
    Set lDoc = lDb.Containers("Tables").Documents("aWr")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Local Table aWr: " & lDoc.Permissions
    Set lDoc = lDb.Containers("Tables").Documents("aWr_ModDes")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Local Table aWr_ModDes: " & lDoc.Permissions
    Set lDoc = lDb.Containers("Tables").Documents("tbl_DataFileVe rsion")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Attached Table tbl_DataFileVersion: " & lDoc.Permissions
    'Forms:
    Set lDoc = lDb.Containers("Forms").Documents("aFrmNotSet")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Form aFrmNotSet: " & lDoc.Permissions
    Set lDoc = lDb.Containers("Forms").Documents("aFrmRun")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Form aFrmRun: " & lDoc.Permissions
    Set lDoc = lDb.Containers("Forms").Documents("aFrmRun_RdDes")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Form aFrmRun_RdDes: " & lDoc.Permissions
    'Reports:
    Set lDoc = lDb.Containers("Reports").Documents("aRptRun")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Report aRptRun: " & lDoc.Permissions
    Set lDoc = lDb.Containers("Reports").Documents("aRptRun_RdDes ")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Report aRptRun_RdDes: " & lDoc.Permissions
    'Macros:
    Set lDoc = lDb.Containers("Scripts").Documents("aMcrRun")
    lDoc.UserName = pcGrpName
    lcMsg = lcMsg & vbCrLf & _
    "Script aMcrRun: " & lDoc.Permissions
    '(And then display lcMsg).

  2. #2
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    I have used the following two Routines for:
    1. To remove all permissions from the 'Users' Group Account.
    2. To set 'Open/Run' permissions to all Containers/Documents.
    Check the code for Constants.
    Code:
    Option Compare Database
    Option Explicit
    
    
    ' Security Setup Programs
    
    
    'Dim grpName As String
    'Dim dbName As String
    Const AdmFullAccess = 1048575
    Const AdmMSysDB = 393230
    Const AdmMSysAO = 393300
    Const AdmMsysModules2 = 244
    Const AdmMSysQ = 393236
    Const AdmMSysRel = 917524
    'Const AdmSumInfoUserDef = 65536
    
    
    Const dbFull = 14
    Const objsFull = 852478
    Const dbFullNo = 393216
    Const objsFullNo = 196097
    Public Function CDefUsers_Grp(ByVal DatabaseName As String) As Integer
    Dim wsp As Workspace, cdb As Database, ctr As Container, doc As Document
    Dim GroupName As String, ctrName As String, docName As String
    Dim L4 As String
    
    
    'Remove All Permissions on Containers & documents
    'of Users Group
    
    
    On Error GoTo CDefUsers_Grp_Err
    
    
    Set wsp = DBEngine.Workspaces(0)
    Set cdb = wsp.OpenDatabase(DatabaseName)
    
    
    wsp.Groups.Refresh
    
    
    GroupName = "Users"
    
    
    For Each ctr In cdb.Containers
      ctrName = ctr.Name
      ctr.UserName = GroupName
      Select Case ctrName
        Case "Databases"
          For Each doc In ctr.Documents
             docName = doc.Name
             doc.UserName = GroupName
             Select Case docName
               Case "MSysDb"
                  doc.Permissions = dbFullNo
             End Select
          Next doc
       Case "Forms"
          ctr.Permissions = objsFullNo
          ctr.Inherit = True
          For Each doc In ctr.Documents
             docName = doc.Name
             doc.UserName = GroupName
             doc.Permissions = objsFullNo
          Next doc
       Case "Modules"
          ctr.Permissions = objsFullNo
          ctr.Inherit = True
          For Each doc In ctr.Documents
             docName = doc.Name
             doc.UserName = GroupName
             doc.Permissions = objsFullNo
          Next doc
       Case "Reports"
          ctr.Permissions = objsFullNo
          ctr.Inherit = True
          For Each doc In ctr.Documents
             docName = doc.Name
             doc.UserName = GroupName
             doc.Permissions = objsFullNo
          Next doc
       Case "Scripts"
          ctr.Permissions = objsFullNo
          ctr.Inherit = True
          For Each doc In ctr.Documents
             docName = doc.Name
             doc.UserName = GroupName
             doc.Permissions = objsFullNo
          Next doc
       Case "Tables"
          ctr.Permissions = objsFullNo
          ctr.Inherit = True
          For Each doc In ctr.Documents
            docName = doc.Name
            doc.UserName = GroupName
            
            L4 = Left$(docName, 4)
            If L4 = "MSys" Or L4 = "~sq_" Then
              GoTo nextloopxxx
            End If
            
            doc.Permissions = objsFullNo
    nextloopxxx:
          Next doc
      End Select
    Next ctr
    CDefUsers_Grp = 0
    CDefUsers_Grp_Exit:
    Set cdb = Nothing
    Set wsp = Nothing
    Exit Function
    
    
    CDefUsers_Grp_Err:
    MsgBox Err & ": " & Err.Description
    CDefUsers_Grp = 1
    Resume CDefUsers_Grp_Exit
    End Function
    Code:
    Public Function DdbUser_Grp(ByVal DatabaseName As String, ByVal GroupName As String) As Integer
    Dim wsp As Workspace, cdb As Database, ctr As Container, doc As Document
    Dim ctrName As String, docName As String
    Dim L4 As String
    
    
    Const dbOpenRun = 2
    Const FrmRptOpenRun = 256
    Const MacOpenRun = 8
    Const tblqryExModify = 244 'All permissions Exluding Modify & Administr
    
    
    'Permissions to Users-Group
    On Error GoTo DdbUser_Grp_Err
    
    
    Set wsp = DBEngine.Workspaces(0)
    Set cdb = wsp.OpenDatabase(DatabaseName)
    
    
    wsp.Groups.Refresh
    
    
    For Each ctr In cdb.Containers
      ctrName = ctr.Name
      ctr.UserName = GroupName
      Select Case ctrName
        Case "Databases"
          For Each doc In ctr.Documents
             docName = doc.Name
             doc.UserName = GroupName
             Select Case docName
               Case "MSysDb"
                  doc.Permissions = doc.Permissions Or dbOpenRun
             End Select
          Next doc
       Case "Forms"
          ctr.Permissions = ctr.Permissions Or FrmRptOpenRun
          ctr.Inherit = True
          For Each doc In ctr.Documents
             docName = doc.Name
             doc.UserName = GroupName
             doc.Permissions = doc.Permissions Or FrmRptOpenRun
          Next doc
       Case "Reports"
          ctr.Permissions = ctr.Permissions Or FrmRptOpenRun
          ctr.Inherit = True
          For Each doc In ctr.Documents
             docName = doc.Name
             doc.UserName = GroupName
             doc.Permissions = doc.Permissions Or FrmRptOpenRun
          Next doc
       Case "Scripts"
          ctr.Permissions = ctr.Permissions Or MacOpenRun
          ctr.Inherit = True
          For Each doc In ctr.Documents
             docName = doc.Name
             doc.UserName = GroupName
             doc.Permissions = doc.Permissions Or MacOpenRun
          Next doc
       Case "Tables"
          ctr.Permissions = ctr.Permissions Or objsFull
          ctr.Inherit = True
          For Each doc In ctr.Documents
            docName = doc.Name
            doc.UserName = GroupName
            
            L4 = Left$(docName, 4)
            If L4 = "MSys" Or L4 = "~sq_" Then
              GoTo nextloopxxxx
            End If
            
            doc.Permissions = doc.Permissions Or tblqryExModify
    nextloopxxxx:
          Next doc
    
    
      End Select
    Next ctr
    DdbUser_Grp = 0
    
    
    DdbUser_Grp_Exit:
    Set cdb = Nothing
    Set wsp = Nothing
    Exit Function
    
    
    DdbUser_Grp_Err:
    MsgBox Err & ": " & Err.Description, , "DdbUser_Grp"
    DdbUser_Grp = 1
    Resume DdbUser_Grp_Exit
    End Function

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

Similar Threads

  1. Setting User Permissions using Dlookup
    By RachelBedi in forum Programming
    Replies: 1
    Last Post: 10-18-2012, 08:36 AM
  2. MDB Permissions
    By esbrega in forum Security
    Replies: 0
    Last Post: 03-08-2012, 03:46 PM
  3. You don't have the necessary permissions
    By registan in forum Access
    Replies: 11
    Last Post: 02-19-2012, 12:53 PM
  4. Replies: 0
    Last Post: 12-17-2010, 07:29 AM
  5. Permissions
    By emccalment in forum Forms
    Replies: 12
    Last Post: 02-17-2010, 04:11 PM

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