User/Group Permissions from Code

S

Stephan Ranocchia

Before I start, I want to quickly say that I have read the Security
FAQ and I'm still having problems. Namely I'm trying to determine if
the current logged in user is part of a group - to allow me to
enable/disable buttons.

However, when I use the Functions in Section 22 of the FAQ, I get an
error indicating that I don't have access to MSysGroupList. The user
group has read permissions to the tables (MSysAccounts, MSysGroups)
but not the queries that Access uses through DBEngine, namely
MSysGroupList, MSysUserList...

Unfortunately the Admin group only has read access to the queries so I
cannot make any changes to the permissions for other groups.

Does anyone have any thoughts about this?

Thanks,
SR

P.S. Access 97
 
A

Albert D. Kallal

Not sure what you are referring to.

However, in code to determine if a user is par of a group I use the
following code


If IsInGroup(CurrentUser(),"DeleteInvoicegrp") then

' code goes here to delete the invoice...

else
msgbox "you do not have permissions to delete invoices"

endif

The IsInGroup code is reproduced below, and can be placed in a standard
module....

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.attcanada.net/~kallal.msn

Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of GrpName

Dim grp As Group
Dim IIG As Boolean
Dim usr As user

IIG = False

For Each usr In DBEngine.Workspaces(0).Users
If usr.Name = UsrName Then GoTo FoundUser
Next

GoTo IIG_Exit

FoundUser:
For Each grp In usr.Groups
If grp.Name = GrpName Then IIG = True
Next

IIG_Exit:
IsInGroup = IIG


End Function
 
S

Stephan Ranocchia

Yes, I use similar code, however, when I call the IsInGroup function, I get
an error re: permissions. Upon closer inspection, the user doesn't have
permission to the MSysGroupList query in the Workgroup File I've created.
Access calls 2 queries when you use DBEngine.Workspaces(0).Users/Groups,
namely MSysUserList, and MSysGroupList. They are 'system queries' in the
..mdw file. They too have permissions and it's these permissions (or lack
there of) that are preventing me from using IsInGroup(). Only the Admins
group has read permission on them, thus I can't edit the permissions.

Any other thoughts?

Thanks,
SR
 
D

david epsom dot com dot au

Which version of Access are you using? I can't find any of my code,
but it did not use to be possible to check user membership of all
groups, because user did not have permission to do so. The normal way
was to check if user was member of a particular group, all other
tests caused exception rather than failing:

on error resume next
strUserName = ws.Groups(strGroup).Users(strUser).Name
if err.number = 0 then .....

BTW, it is possible to change the permissions on those queries.

(david)
 
S

Stephan Ranocchia

That was it! Thanks for the tip. I guess I had removed the Users group
from the member!

Phew. 1 problem down, only a few hundred to go...

SR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top