ACC2000: How to Add a User to a Group with CreateUser Method

ID: Q210418


The information in this article applies to:

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


SUMMARY

To add a user to an existing group with code, you must use the CreateUser method twice: once to create the new user for that Microsoft Access session, and again to create the user for the group.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


MORE INFORMATION

The following sample function called CUser() demonstrates how to create a user named MyName for the Users group:

  1. Create a module and type the following procedure:


  2. 
    Function CUser (uname As String, upin As String, upwd As String, _
       gname As String)
    
       Dim u  As User, w As WorkSpace, g As Group
       Set w = dbengine.workspaces(0)          'The default workspace.
       Set u = w.CreateUser(uname, upin, upwd) 'Create a user for the
                                               'Access session.
       w.users.Append u                        'Add user to workspace.
       w.users.Refresh
       Set g = w.groups(gname)
       Set u = g.CreateUser(uname)             'Create a user for a
                                                group.
       g.users.Append u                        'Add new user to group.
       g.users.Refresh
    End Function 
  3. To test this function, type the following line in the Immediate window, and then press ENTER:


  4. 
    ? CUser ("MyName","1234","MyName","Users") 
  5. Save the module and close the Visual Basic Editor.


  6. On the Tools menu, click Security, and then click User And Group Permissions.
    Note that the new user appears in the Users/Group Name box.



REFERENCES

For more information about the CreateUser method, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type "CreateUser" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words: inf


Keywords          : kbprg kbdta PgmObj ScrtUsr 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: July 6, 1999