Determining what group a user belongs to

helena

Registered User.
Local time
Today, 03:56
Joined
Nov 7, 2000
Messages
15
Is there a function similar to CurrentUser() that will return what group the current user belongs to?
If not, has anyone used their code to return the group name?

Thanks in advance

Helena
 
No there is no such function in Access/VBA. But you could go in to the .MDW file that is being used with the App and use a query to return all the Groups a user belongs to. I suppose you could write a fuction that does this for the current user.
 
Thanks for that bob, this is the answer. I have used this code to find out what groups the current user is in, then appended those group names to a table which is linked to a menu structure table, in other words depending what groups a user belongs to they will see different menu items in a combo box list based on the menu table. This avoids them logging in with different user name aliases to see different menu options.
Code follows below:

Public Function GroupX()

Dim wrkDefault As Workspace
Dim usrLoop As User
Dim grpLoop As Group
Dim dbs As Database
Dim rstMenuPermissions As Recordset

'Initialise workspace, database and recordset
Set wrkDefault = DBEngine.Workspaces(0)
Set dbs = CurrentDb
Set rstMenuPermissions = dbs.OpenRecordset("tblMenuPermissions", dbOpenTable)


'Working with the default workspace...
With wrkDefault

'Find Current username object in the default Workspace 's Users collection.
For Each usrLoop In .Users

If usrLoop.Name = CurrentUser() Then

'Enumerate all Group objects in each the CurrentUser's Groups collection.
If usrLoop.Groups.Count <> 0 Then
For Each grpLoop In UsrLoop.Groups

'Append the group name to groups table
With rstMenuPermissions
.AddNew ' Add new record.
!MG_GroupName = grpLoop.Name ' Add data.
.Update ' Save changes.
End With

Next grpLoop
End If

End If

Next usrLoop


'Finish working with workspace
End With

' Close recordset to free memory.
rstMenuPermissions.Close
' Free memory used by object variable.
Set dbs = Nothing

End Function

[This message has been edited by helena (edited 12-04-2000).]
 
Short Function to Return If CurrentUser is in Group

Here's a much simpler adaptation of that code I'm using in conjuction with hide/view toolbar code to display menus based upon if a user is part of a certain group.


Function IsInGroup(grpName As String) As Boolean
Dim daGroups As Object
IsInGroup = False
Set daGroups = DBEngine.Workspaces(0).Users(CurrentUser).Groups
For Each x In daGroups
If x.Name = grpName Then IsInGroup = True
Next x
End Function
 

Users who are viewing this thread

Back
Top Bottom