How to hide controls based currentuser()'s group?

Karl K

Registered User.
Local time
Today, 04:45
Joined
Feb 2, 2000
Messages
41
I want to set the Visible property on some buttons to False based on the CurrentUser()'s Group membership. Is there some way to determine this? Users cant get to the admin functions, etc. On Load, I could check by currentuser's name, but they will change. How to code it based on group?

Thanks for any ideas.
 
Hi Karl,

I found a solution for your problem. Even though it is working fine, I am not really convinced by it. There should be an easier way! So if you got any other ideas in the meantime, please let me know.

First I am looping through the users collection to see, what user is the current one.
As this user could be member of more than one group, I am looping through all the his groups plus I used a boolean type variable to check whether one of the groups is the one where you want to hide the command button.

Hope this helps!

Cheers,
Judith

Private Sub Form_Open(Cancel As Integer)
Dim wrkDefault As Workspace
Dim usrLoop As User
Dim grpLoop As Group
Dim bolGroupmember As Boolean

Set wrkDefault = DBEngine.Workspaces(0)
bolGroupmember = False

With wrkDefault

For Each usrLoop In .Users

If usrLoop.Name = CurrentUser Then

For Each grpLoop In usrLoop.Groups
'replace groupname with your groupname
If grpLoop.Name = "grpGroupname" Then
bolGroupmember = True
End If

Next grpLoop
End If

Next usrLoop

If bolGroupmember = True Then
'replace formname and buttonname with your names
Forms!frmFormname!cmdbuttonname.Visible = False
Else
'replace formname and buttonname with your names
Forms!frmFormname!cmdbuttonname.Visible = True
End If

End With

End Sub
 
Yes, this seems inordinately complex. Is there some way to simply say

if currentuser ?is a member of group? Admins or ...[2nd group] then
cmdAdminfunction.visible = true
else
cmdAdminfunciton.visible = false
end if

Anyone have any suggestions? It would be nice if currentuser had some properties, but it doesn't seem to.
 

Users who are viewing this thread

Back
Top Bottom