UsersGroups - Microsoft Access security groups and users output to a table


Function fnUsersGroups() As String
Dim wrk As DAO.Workspace
Dim db As DAO.Database
Dim usr As DAO.User
Dim grp As DAO.Group
Dim rst As DAO.Recordset
Dim strSQL As String

Set db = CurrentDb
strSQL = "DELETE * FROM [tblUsersGroups];"
db.Execute strSQL
strSQL = "SELECT * FROM [tblUsersGroups];"
Set rst = db.OpenRecordset(strSQL)
Set wrk = DBEngine.Workspaces(0)
For Each grp In wrk.Groups
     For Each usr In grp.Users
     With rst
         .AddNew
         !User = usr.Name
         !Group = grp.Name
         .Update
     End With
     Next usr
     Next grp
End Function