Determine the Groups for CurrentUser

V

Vayse

Hi
I want to enable a button if the user is a member of the Managers group.
How can I determine through code what Groups a user is in?
Thanks
Vayse

P.S. Here's what I have so far

Dim accUser As dao.User
Const conMANAGER As String = "Managers"
Dim iLoop As Integer

accUser.Name = CurrentUser ' Fails here
For iLoop = 0 To accUser.Groups.Count
If accUser.Groups(iLoop).Name = conMANAGER Then
Me.cmdDelete.Enabled = True
End If
Next
 
J

Jeff Conrad

Here is a past post of mine which should help:
There is code for this in the Security FAQ:

Security FAQ (the Security Bible):
http://support.microsoft.com/?kbid=207793
More specifically:
http://support.microsoft.com/default.aspx?scid=/support/access/content/secfaq.asp#_Toc493299691

Here is also some code posted by MVP Albert Kallal:

The following module is created:
+++++++++++++++++++++++++++++++++++++++++++++
Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of GrpName
'--
'http://www.attcanada.net/~kallal.msn/RidesSec/index.html
'--Dec 16th 2002 microsoft.public.access.security
'Albert D.kallal
'Edmonton, Alberta Canada
'kallal@ msn.com
'www.attcanada.net/~kallal.msn

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
+++++++++++++++++++++++++++++++++++++++++++++

And the code for checking goes like this:

If (IsInGroup(CurrentUser(), "nameofgroup") = True) Then
' Execute Code
Else
' Execute different code
End If
Hope that helps,
--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

in message:
 
V

Vayse

Thanks!
Jeff Conrad said:
Here is a past post of mine which should help:

There is code for this in the Security FAQ:

Security FAQ (the Security Bible):
http://support.microsoft.com/?kbid=207793
More specifically:
http://support.microsoft.com/default.aspx?scid=/support/access/content/secfaq.asp#_Toc493299691

Here is also some code posted by MVP Albert Kallal:

The following module is created:
+++++++++++++++++++++++++++++++++++++++++++++
Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of GrpName
'--
'http://www.attcanada.net/~kallal.msn/RidesSec/index.html
'--Dec 16th 2002 microsoft.public.access.security
'Albert D.kallal
'Edmonton, Alberta Canada
'kallal@ msn.com
'www.attcanada.net/~kallal.msn

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
+++++++++++++++++++++++++++++++++++++++++++++

And the code for checking goes like this:

If (IsInGroup(CurrentUser(), "nameofgroup") = True) Then
' Execute Code
Else
' Execute different code
End If

Hope that helps,
--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

in message:
 

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