ACC: How to Add a User to a Group with CreateUser Method
ID: Q112063
|
The information in this article applies to:
-
Microsoft Access versions 2.0, 7.0, 97
SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.
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.
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 with Microsoft Access 2.0" manual.
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:
NOTE: In the following sample code, an underscore (_) at the end of a
line is used as a line-continuation character. Remove the underscore
from the end of the line when re-creating this code Access Basic.
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 Debug window (or
the Immediate window in version 2.0), and then press ENTER:
? CUser ("MyName","1234","MyName","Users")
- On the Tools menu point to Security, and then click User And Group
Permissions.
NOTE: In version 2.0, on the Security menu, click Permissions.
Note that the new user appears in the Users/Group Name box.
REFERENCES
For more information about the CreateUser method, search the Help Index for
CreateUser or ask the Microsoft Access 97 Office Assistant.
Additional query words:
Keywords : kbprg PgmObj ScrtUsr
Version : WINDOWS:2.0,7.0,97
Platform : WINDOWS
Issue type : kbhowto
|