Solved

Modifying Group Permissions Programatically

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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