Solved

Modifying Group Permissions Programatically

Posted on 2008-11-02
3
355 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
  • 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
update query 4 28
vba for Saving access tables to excel with password 4 29
Random times with 12/24 hour switching 9 28
Microaoft Access on a SBS 2011 Server 4 21
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

821 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