Solved

Modifying Group Permissions Programatically

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now