Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print and List Users/Groups programmatically?

Status
Not open for further replies.

tgikristi

Technical User
Jul 31, 2002
39
US
I found a way to print a list of the users and groups in a secured database manually from the MSDN website/Access Help (Tools menu, Security, User And Group Accounts, click Print Users And Groups), but I am wondering if the same can be accomplished using code?

Sorry for my ignorance.

Also, is there a way to make a listbox return a list of all the users and their associated groups? I've read all the posts about the Help Group Object, Groups Collection, User Object, and Users Collection Example, and I've tried many versions of the code to enumerate all the users and groups, but (I said I was ignorant) I think this applies to the current user? or something? and it isn't working to print off a whole list of all the users, etc. when I try to tie the code to a Print command button, or some such. I don't know what I am doing incorrectly...any ideas?

Any help would be greatly appreciated.

Thanks,
tgikristi
 
The Access <version nbr> Developers Handbook, at least for A2K2 and, I trhink A97, has a routine to programatically pull all groups and members of groups. If you don't have quick access to that volume, find a book store with a copier and bring quarters. I think it's more than a page of code. Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Hey. Forget my suggestion about the copying machine. i was looking at some old listings looking for a way to solve a totally unrelated security proble, and then realized you should be ableto modify this code to get to all groups and all users within a group,

Hey, what the hell, you're up to a liitle challenge aren't you. Here's the code:

Function IsUserInGroup(strUser As String, strGroup As String) As
Boolean
'Returns True if the user is in the group.
'Example: IsUserInGroup(CurrentUser(), &quot;Admins&quot;)
Dim wk As Workspace
Dim grx As Groups
Dim grp As Group
Dim usx As Users
Dim usr As User

Set grx = DBEngine(0).Groups
For Each grp In grx
If grp.Name = strGroup Then
Set usx = grp.Users
For Each usr In usx
If usr.Name = strUser Then
IsUserInGroup = True
Exit For
End If
Next
End If
Next

Set usr = Nothing
Set usx = Nothing
Set grp = Nothing
Set grx = Nothing
End Function

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
When I tried this code to generate a 2-column listbox that shows all users and then the security group to which they belong, all I get is a listbox that has 2 columns (no headers) with the value &quot;true&quot; in the first column and that's it. If someone is bored and doesn't mind taking a look at this code to see where I may have gone astray, I would appreciate it SO SO much!

Thanks,
tgikristi

--------
Function fListFill(List34 As Control, varID As Variant, varRow As Variant, _
varCol As Variant, varCode As Variant) As Variant
Dim varRet As Variant
Dim cat As ADOX.Catalog
Dim usr As ADOX.User
Dim grp As ADOX.Group
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Static sintNumUsers As Integer
sintNumUsers = cat.Users.Count

Const COLUMN_COUNT = 2

Select Case varCode

Case acLBInitialize
varRet = True
Case acLBOpen
varRet = Timer
Case acLBGetRowCount
varRet = sintNumUsers
Case acLBGetColumnWidth
Select Case varCol
Case 0:
varRet = -1
Case 1:
varRet = -1
End Select

Case acLBGetColumnCount
varRet = COLUMN_COUNT

Case acLBGetValue
Select Case varCol
Case 0:
If varRow = 0 Then
varRet = &quot;User&quot;
Else
For Each usr In cat.Users
strUsers.AddItem usr.Name
Next usr
varRet = varRow.strUsers
End If
Case 1:
If varRow = 0 Then
varRet = &quot;Access Group&quot;
Else
For Each usr In cat.Users
strGroups.AddItem usr.Groups
Next usr
varRet = varRow.strGroups
End If
End Select
End Select

fListFill = varRet
End Function


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top