list of users

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

For days now I am trying.
Is it Possible for me to get a list of Users and a list of Group Memebership
onto a table of query in my database
 
OK. It's just a matter of writing the output to a recordset instead of to
debug. That's standard programming, not really to do with the list of users.

Here's (untested, just wrote it) code for the sample list given
(original code has >)

This uses DAO, meaning you must have a reference to DAO not ADO.

It also assumes you already have a blank table with a field "UserName".
Function faq_ListGroupsOfUser (strUserName As String)
Dim ws As WorkSpace
Dim usr As User
Dim i As Integer
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("YourTable")
Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(strUserName)
For i = 0 To usr.Groups.count - 1
'> Debug.Print usr.Groups(i).Name

rst.AddNew
rst!UserName= usr.Groups(i).Name
rst.Update
Next i
End Function

rst.Close
Set rst = Nothing
 
Umm...End Function should be the last line...told you it was untested :-)
And this puts out Username and Groupname if you have those table fields - you
get the idea.
Function faq_ListGroupsOfUser (strUserName As String)
Dim ws As WorkSpace
Dim usr As User
Dim i As Integer
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("YourTable")
Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(strUserName)
For i = 0 To usr.Groups.count - 1
'> Debug.Print usr.Groups(i).Name

rst.AddNew
rst!UserName = strUserName
rst!GroupName = usr.Groups(i).Name
rst.Update

rst.Close
Set rst = Nothing
 
And to do it for all users...put this in something which calls the faq
function.
(How'm I doing?)
(comes roughly from Help on Users Collection example)


Dim wrkDefault As Workspace
Dim usrLoop As User

Set wrkDefault = DBEngine.Workspaces(0)

With wrkDefault
For Each usrLoop In .Users
faq_ListGroupsOfUser (usrLoop.Name)
Next usrLoop
end with
 
Hey!

Thanks I get the idea. However I should tell you that I am just getting
started in VB. Where should I place this "untested code"?

Thanks
 
With respect, there's a weeny problem here. Manipulating Users and Groups with
code is a very sophisticated thing to do. You're supposed to wear a Tuxedo to
a party like that! Most apps just don't need to do anything like it.

I appreciate your enthusiasm, but this is now into general Access programming
and we could go on forever. If you're just experimenting/learning, why start
off at the deepest end?

I can't tell you where to place the code. The original faq was written as a
function, meaning it's a piece of code that can be called from other code
(such as my last one). Where you place my last one is anywhere you like. For
instance, create a new form, place a command button on it, and place it in the
code for the command button. That's how I'd test-run code in a very simple
way.

Chris
 
Back
Top