Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Modifying Group Permissions Programatically

Posted on 2008-11-02
3
Medium Priority
?
360 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 85
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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

916 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