How can I identify the user group in VBA code

M

Marco

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
 
A

Allen Browne

Marco said:
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
 
D

Daniel Pineault

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/micro...read/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.
 

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