Enable/Disable a Form Control Based on Security Group Permissions

B

BenS

How do I enable or disable a control in a form based on a user’s security
group membership? For example: If I have a checkbox on a form (call it box1),
I want box1 to be enabled if the user who opened Access is a member of a
security group called “Breaker Test Admin.†For members of any other group
(except of course “Adminsâ€), box1 should be disabled.

Thank you, for your help!
 
S

Scott McDaniel

How do I enable or disable a control in a form based on a user’s security
group membership? For example: If I have a checkbox on a form (call it box1),
I want box1 to be enabled if the user who opened Access is a member of a
security group called “Breaker Test Admin.” For members of any other group
(except of course “Admins”), box1 should be disabled.

Thank you, for your help!

You must first determine if the Currentuser is a member of your group; you can use the function below to do this. In
your form's Open or Load event, do something like this:

Me.box1.Enabled = faq_IsUserInGroup("Breaker Test Admin", CurrentUser) OR faq_IsUserInGroup("Admins", CurrentUser)

In my apps, I determine if a user is a member of the Admins group, then set a class variable so that I don't have to
continually poll the workspace; you might consider doing something similar, if you'll have a lOT of calls to this code.

Put the code below in a Standard Module:

Function faq_IsUserInGroup (strGroup As String, strUser as String) As Integer
' Returns True if user is in group, False otherwise
' This only works if you're a member of the Admins group.
Dim ws As WorkSpace
Dim grp As Group
Dim strUserName as string

Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next
strUserName = ws.groups(strGroup).users(strUser).Name
faq_IsUserInGroup = (Err = 0)
End Function

From the Microsoft Access ULS FAQ:
http://support.microsoft.com/default.aspx?scid=/support/access/content/secfaq.asp#_Toc493299691

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 

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