Microsoft Knowledge Base Email Alertz

KBAlertz.com: Advanced: Requires expert coding, interoperability, and multiuser skills.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 123079 - Last Review: January 19, 2007 - Revision: 2.4

ACC: Sample Functions to Check User, Group Info

This article was previously published under Q123079

On This Page

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article contains several sample user-defined functions that you can use to do the following:

  • Return a list of users in the current system database.
  • Return a list of groups in the current system database.
  • Return a list of users in a specified group.
  • Return a list of groups to which a specified user belongs.
  • Determine if the current user belongs to a specified group.
This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.

MORE INFORMATION

You can use the following sample functions to return user and group information in the current system database. Note that each function assumes there is a user called Developer who is a member of the Admins group, and that the Developer account has no password.

The Sample Functions

   '********************************************************
   ' Declarations section of the module
   '********************************************************

   Option Compare Database
   Option Explicit

   Function ListUsersInSystem ()
   '****************************************************************
   ' Purpose: Lists users in the current system database.
   ' Accepts: No arguments.
   ' Returns: A list of users in the current system database.
   ' Assumes: The existence of a user called Developer in the Admins
   '          group, with no password.
   '****************************************************************

   On Error GoTo err_ListUsersInSystem

   Dim MyWorkSpace As WorkSpace, i As Integer

   ' Create a new workspace as a member of the Admins group.
   Set MyWorkSpace = DBEngine.CreateWorkspace("SPECIAL", "Developer", "")

   For i = 0 To MyWorkSpace.Users.count - 1
        Debug.Print MyWorkSpace.Users(i).Name
   Next i

   MyWorkSpace.Close
   Exit Function

   err_ListUsersInSystem:
   If Err = 3029 Then
        MsgBox "The account used to create the workspace does not exist"
   Else MsgBox Error(Err)
   End If

   MyWorkSpace.Close
   Exit Function

   End Function

   Function ListGroupsInSystem ()
   '****************************************************************
   ' Purpose: Lists groups in the current system database.
   ' Accepts: No arguments.
   ' Returns: A list of groups in the current system database.
   ' Assumes: The existence of a user called Developer in the Admins
   '          group, with no password.
   '****************************************************************

   On Error GoTo err_ListGroupsInSystem

   Dim MyWorkSpace As WorkSpace, i As Integer

   ' Create a new workspace as a member of the Admins group.
   Set MyWorkSpace = DBEngine.CreateWorkspace("SPECIAL", "Developer", "")
   For i = 0 To MyWorkSpace.Groups.count - 1
        Debug.Print MyWorkSpace.Groups(i).Name
   Next i

   MyWorkSpace.Close

   Exit Function

   err_ListGroupsInSystem:
   If Err = 3029 Then
        MsgBox "The account used to create the workspace does not exist"
   Else MsgBox Error(Err)
   End If

   MyWorkSpace.Close
   Exit Function

   End Function

   Function ListUsersOfGroup (GroupName As String)
   '****************************************************************
   ' Purpose: Lists users who are members of the specified group in
   '          the current system database.
   ' Accepts: The name of a group.
   ' Returns: A list of users in the specified group.
   ' Assumes: The existence of a user called Developer in the Admins
   '          group, with no password.
   '****************************************************************

   On Error GoTo err_ListUsersOfGroup

   Dim MyWorkSpace As WorkSpace, i As Integer
   Dim MyGroup As Group

   ' Create a new workspace as a member of the Admins group.
   Set MyWorkSpace = DBEngine.CreateWorkspace("SPECIAL", "Developer", "")

   Set MyGroup = MyWorkSpace.Groups(GroupName)

   For i = 0 To MyGroup.Users.count - 1
        Debug.Print MyGroup.Users(i).Name
   Next i

   MyWorkSpace.Close
   Exit Function

   err_ListUsersOfGroup:
   If Err = 3265 Then
        MsgBox UCase(GroupName) & " isn't a valid group name", 16, "Error"
   ElseIf Err = 3029 Then
        MsgBox "The account used to create the workspace does not exist"
   Else MsgBox Error(Err)
   End If

   MyWorkSpace.Close
   Exit Function

   End Function

   Function ListGroupsOfUser (UserName As String)
   '****************************************************************
   ' Purpose: Lists the groups to which a specified user belongs.
   ' Accepts: The name of a user.
   ' Returns: A list of groups for the specified user.
   ' Assumes: The existence of a user called Developer in the Admins
   '          group, with no password.
   '****************************************************************

   On Error GoTo err_ListGroupsOfUser

   Dim MyWorkSpace As WorkSpace, i As Integer
   Dim MyUser As User

   ' Create a new workspace as a member of the Admins group.
   Set MyWorkSpace = DBEngine.CreateWorkspace("SPECIAL", "Developer", "")

   Set MyUser = MyWorkSpace.Users(UserName)

   For i = 0 To MyUser.Groups.count - 1
        Debug.Print MyUser.Groups(i).Name
   Next i

   MyWorkSpace.Close
   Exit Function

   err_ListGroupsOfUser:
   If Err = 3265 Then
        MsgBox UCase(UserName) & " isn't a valid user name", 16, "Error"
   ElseIf Err = 3029 Then
        MsgBox "The account used to create the workspace does not exist"
   Else MsgBox Error(Err)
   End If

   MyWorkSpace.Close
   Exit Function

   End Function

   Function CurrentUserInGroup (GroupName As String)
   '****************************************************************
   ' Purpose: Determines if the current user belongs to the specified
   '          group.
   ' Accepts: The name of a group.
   ' Returns: True if the current user is a member of the specified
   '          group, False if the current user is not a member of
   '          the group.
   ' Assumes: The existence of a user called Developer in the Admins
   '          group, with no password.
   '****************************************************************

   On Error GoTo err_CurrentUserInGroup

   Dim MyWorkSpace As WorkSpace, i As Integer
   Dim MyGroup As Group, MyUser As User

   ' Create a new workspace as a member of the Admins group.
   Set MyWorkSpace = DBEngine.CreateWorkspace("SPECIAL", "Developer", "")

   Set MyGroup = MyWorkSpace.Groups(GroupName)
   Set MyUser = MyWorkSpace.Users(CurrentUser())
   For i = 0 To MyGroup.Users.count - 1
        If MyGroup.Users(i).Name = MyUser.Name Then
             CurrentUserInGroup = True
             Exit Function
        End If
   Next i

   CurrentUserInGroup = False
   MyWorkSpace.Close
   Exit Function

   err_CurrentUserInGroup:
   If Err = 3265 Then
        MsgBox UCase(GroupName) & " isn't a valid group name", 16, "Error"
        CurrentUserInGroup = False
   ElseIf Err = 3029 Then
        MsgBox "The account used to create the workspace does not exist"
   Else MsgBox Error(Err)
   End If

   MyWorkSpace.Close
   Exit Function

   End Function
				
To test these functions, run them in the Debug window (or Immediate window in Microsoft Access 2.0). For example, to test the ListGroupsOfUser() function, follow these steps:

  1. Open the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access 2.0).
  2. Create a new module and enter the sample functions above.
  3. On the View menu, click Debug Window (or Immediate Window in Microsoft Access 2.0.)
  4. In the Debug window, type the following line, and then press ENTER:
    ? ListGroupsOfUser("Admin")

REFERENCES

For more information about Users, search for User Object, and then User Object using the Microsoft Access Help Index.

For more information about Groups, search for Group Object, and then Group Object using the Microsoft Access Help Index.

APPLIES TO
  • Microsoft Access 2.0 Standard Edition
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition
Keywords: 
kbhowto kbprogramming kbusage KB123079
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please