Microsoft KB Archive/210418

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

Article ID: 210418

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210418



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. 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.



MORE INFORMATION
The following sample function called CUser demonstrates how to create a user named MyName for the Users group:   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   To test this function, type the following line in the Immediate window, and then press ENTER: ? CUser ("MyName","1234","MyName","Users")  Save the module and close the Visual Basic Editor. 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.

