Solved

Modifying Group Permissions Programatically

Posted on 2008-11-02
3
356 Views
Last Modified: 2008-11-04
I have a form that allows my admins to create groups. I want all of these groups to have the same permissions so I created a test group and set the permissions, then through code looked at what the permissions were. But if I change some form permissions and such the permission return remains the same. How can I, down to a single object, set permissions through code. Below is the routine I use currently.

Would I have to have a template group which I somehow copy each time so that the permissions are the same?
Dim db As Database
Dim con As Container
Dim doc As Document
            
Set db = CurrentDb
            Set con = db.Containers("Databases")
            Set doc = con.Documents("MSysdb")
            doc.UserName = strType & "_" & txtGroupName
            'Set group permissions
            doc.Permissions = 2
            Set db = Nothing
            Set con = Nothing
            Set doc = Nothing

Open in new window

0
Comment
Question by:bejhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84
ID: 22865701
You must add to the Document's permissions:

doc.Permissions = doc.Permissions AND 2

doc.Permissions = doc.Permissions AND NOT 2

That said, you cannot modify permissions for the MSysDB table ... this is a System table, and is controlled internally.
0
 
LVL 1

Author Comment

by:bejhan
ID: 22870391
I understand that you must AND to add to the permissions. I mean when I check a group's permissions once I have changed something through User and Group permissions and I check permissions through this method, it just returns the same value, wouldn't it need to change to reflect the changes?
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 22875317
That would depend ... often, when you add a Permission to a Document, you're actually adding several different permissions "grouped" as one. For example, when you add the dbSecWriteDef permission, you're actually adding the dbSecFrmRptWriteDef (i.e. &H8 permission), the dbSecReadDef and the dbSecDelete permission ... so if you added dbSecWriteDef, checked the "value", then added the dbSecReadDef permission, you'd find that the value hadn't changed (since simply adding dbSecWriteDef also adds dbSecReadDef).

Also, if you must work with security permissions via VBA code, I'd urge you to get your hands on these books:

Jet Database Engine Programmer's Guide (second edition)
Real World Microsoft Access Database Protection and Security (Garry Robinson)
Developer's Handbook - there are different versions for the various versions of Access, although the 2003 version is the last one I've seen

The first two are invaluable when working with security; the third gives you quite a few real-world examples regarding working with VBA and permissions.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL using aggregate function with HAVING / WHERE clause. 8 51
GA Ribbon creator 9 64
Combo box with two columns question 7 40
Using a combo box to search a form. 3 36
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question