Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: How can I identify the user group in VBA code

Geek News

How can I identify the user group in VBA code
Marco 12/10/2008 12:11:01 PM
Hi. i would like to give some permissions in my form directly from VBA code.

How can I identify to which group the current user belong?

Thanks,
marco
Re: How can I identify the user group in VBA code
"Allen Browne" <AllenBrowne[ at ]SeeSig.Invalid> 12/10/2008 12:44:49 PM
"Marco" <Marco[ at ]discussions.microsoft.com> wrote in message
news:465AA353-F43B-4CF0-ACF7-C55AF3241B37[ at ]microsoft.com...
[Quoted Text]
> Hi. i would like to give some permissions in my form directly from VBA
> code.
>
> How can I identify to which group the current user belong?

A user can be in multiple groups, so you need to ask the question:
Is the user in the Admin (or whatever) group?
rather than
Which group is the user in?

Function IsUserInGroup(strUser As String, strGroup As String) As Boolean
Dim varDummy As Variant
On Error Resume Next
varDummy = DBEngine(0).Users(strUser).Groups(strGroup).Name
IsUserInGroup = (Err.Number = 0)
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

Re: How can I identify the user group in VBA code
Daniel Pineault 12/10/2008 3:19:02 PM
You can try,

Public Sub EnumUserGroups(strUser As String)
' Enumerate the groups a specific user belongs to
' Source: Graham R Seach - MS Access MVP
'
http://groups.google.ca/group/microsoft.public.access.security/browse_thread/thread/3527785593af7279/b0d043a4d1dd6886
Dim wrk As DAO.Workspace
Dim varGroup As Variant

Set wrk = DBEngine(0)

Debug.Print "Groups to which user '" & strUser & "' belongs..."
For Each varGroup In wrk.Users(strUser).Groups
Debug.Print vbTab & varGroup.Name
Next varGroup

Set wrk = Nothing
End Sub

--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Allen Browne" wrote:

[Quoted Text]
> "Marco" <Marco[ at ]discussions.microsoft.com> wrote in message
> news:465AA353-F43B-4CF0-ACF7-C55AF3241B37[ at ]microsoft.com...
> > Hi. i would like to give some permissions in my form directly from VBA
> > code.
> >
> > How can I identify to which group the current user belong?
>
> A user can be in multiple groups, so you need to ask the question:
> Is the user in the Admin (or whatever) group?
> rather than
> Which group is the user in?
>
> Function IsUserInGroup(strUser As String, strGroup As String) As Boolean
> Dim varDummy As Variant
> On Error Resume Next
> varDummy = DBEngine(0).Users(strUser).Groups(strGroup).Name
> IsUserInGroup = (Err.Number = 0)
> End Function
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net