INF: Sample Function to Return Current User's Groups
  
PSS ID Number: Q109721
Article last modified on 10-04-1994
 
1.00 1.10
 
WINDOWS
 

---------------------------------------------------------------------
The information in this article applies to:
 
 - Microsoft Access versions 1.0 and 1.1
---------------------------------------------------------------------
 
SUMMARY
=======
 
This article describes a sample Access Basic function to get a list of
groups the current user belongs to in the current Microsoft Access system.
 
Notes
-----
 
 - The technique described below relies on the use of system tables
   stored with your database. These tables are undocumented and are
   subject to change in future versions of Microsoft Access.
 
 - This article assumes that you are familiar with Access Basic and with
   creating Microsoft Access applications using the programming tools
   provided with Microsoft Access. For more information on Access Basic,
   please refer to the "Introduction to Programming" manual.
 
MORE INFORMATION
================
 
The following function returns a comma-separated list of the groups in the
Microsoft Access system to which the current user belongs. The function
takes one argument that lists the complete path and filename for the
SYSTEM.MDA file you want to query:
 
   '***********************************
   ' Declarations Section of the Module
   '***********************************
   Option Explicit
 
   '=========================================================
   ' The following CurrentUserGroup() function returns a list
   ' of groups to which the current user belongs.
   '=========================================================
 
   Function CurrentUsersGroups (SysDB As String)
      Dim DB As Database
      Dim QD As QueryDef
      Dim DS As Dynaset
      Dim CurrUser As String, Groups As String
      Dim Counter As Integer
 
      Set DB = OpenDatabase(SysDB)
      Set QD = DB.OpenQueryDef("MSysUserMemberships")
      QD![UserName] = User()
      Set DS = QD.CreateDynaset()
 
      DS.MoveLast
      DS.MoveFirst
 
      For Counter = 1 To DS.RecordCount
         Groups = Groups & IIf(Len(Groups) > 0, ",", "") & DS![Name]
         DS.MoveNext
      Next Counter
 
      DS.Close
      DB.Close
 
      CurrentUsersGroups = Groups
 
   End Function
 
To run the function where the SYSTEM.MDA file is located in the ACCESS
directory on the C drive, type the following in the module's Immediate
window and press ENTER:
 
   ? CurrentUsersGroups("C:\ACCESS\SYSTEM.MDA")
 
If you are logged into the Microsoft Access system as the Admin user, and
you have not changed the default groups to which the Admin user belongs,
you will receive the following list when the above function is run:
 
   Admins,Users
 
REFERENCES
==========
 
Microsoft Access "Language Reference," version 1.0, pages 88- 90, 198-199,
311-312, 352-354, and 390-391
 
Microsoft Access "Introduction to Programming," version 1.0, Chapter 8,
"Manipulating Data," pages 137-138
 
Additional reference words: 1.00 1.10 security
KBCategory: kbusage
KBSubcategory: ScrtOthr
=============================================================================
Copyright Microsoft Corporation 1994.
