Enable/Disable a Control in a Form Based on Security Group Permiss

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!
 
D

DaveT

Set the form's open event to use the function below, for example:

Box1.Enabled = GetUserRights()

....

Public Function GetUserRights() As Boolean
Dim ws As DAO.Workspace
Dim usrLoop As User
Dim grpLoop As Group

Dim strUser As String
Dim strGroupName As String

On Error GoTo TrapIt:

GetUserRights = False

strUser = CurrentUser

Set ws = DBEngine.CreateWorkspace("", GetDevAdminName(), GetDevAdminPW())
'Change the Admin Get name/pw to your admin user name and admin password

With ws

For Each usrLoop In .Users
If usrLoop.Name = strUser Then

If usrLoop.Groups.Count <> 0 Then
For Each grpLoop In usrLoop.Groups
strGroupName = grpLoop.Name
If strGroupName = "Admins" Then
GetUserRights = True
Exit For
ElseIf strGroupName = "Breaker Test Admin" Then
GetUserRights = True
Exit For
End If

Next grpLoop
Else 'should not get here!
GetUserRights = False
End If
End If


Next usrLoop

End With

EnterHere:
On Error Resume Next
ws.Close
Set ws = Nothing

Exit Function

TrapIt:
GetUserRights = False
ReportErrVB Err.Number, "Error in procedure: GetUserRights", Err.Description
Resume EnterHere

End Function
 
D

DaveT

The ReportErrVB is a function I use. You should replace that line with
something such as:

MsgBox Err.Number & " " & Err.Description
 
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.

Answered in microsoft.public.access.security.

Please don't CrossPost ... if you feel you need to post to more than one newsgroup (and that is RARELY needed) then
please Multipost so that answers from all newsgroups will show. Cross posting can cause newsgroup veterans to disregard
your postings, and rob you of valuable expertise.
Thank you, for your help!

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

BenS

Hi Scott,

Thank you, for your reply to my post on AccessMonster. While I've read
numerous posts on various forums over the years, this is the first time I've
posted a question of my own. Apparently, I faux pas'd by posting on more than
a single forum, so I apologize.

Would you explain how to mulitpost so in the future I (and others who read
this) don't do the samething?

Thanks, again.

--Ben
 
B

BenS

Hi Dave,

I'm getting a Compile error: Sub or Function not defined message where I
replaced "GetDevAdminName" with my user name.

Any suggestions? (I'm an electrical engineering-type person--not a software
developer, so I'm probably in over my head on this.)

--Ben
 

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