Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q210418
Advanced: Requires expert coding, interoperability, and multiuser skills.

↑ Back to the top


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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

↑ Back to the top


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:
    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
    					
  2. To test this function, type the following line in the Immediate window, and then press ENTER:
    ? CUser ("MyName","1234","MyName","Users")
    					
  3. Save the module and close the Visual Basic Editor.
  4. 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.

↑ Back to the top


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.

↑ Back to the top


Keywords: KB210418, kbprogramming, kbhowto, kbdta

↑ Back to the top

Article Info
Article ID : 210418
Revision : 2
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 344