Creating and Deleting Users

Using DAO, you can create a new user account that can then be added to one or more groups. The following code shows how to create a new user. The basic procedure is to create the user with the CreateUser method, and then append it to the Users collection.

Public Function CreateUserAccount(strUserName As String, _ strPID As String, strPassword As String) Dim wrk As DAO.Workspace Dim usr As DAO.User

Set wrk = DBEngine(0)

On Error GoTo CreateUserAccountErr

'Create the new user

Set usr = wrk.CreateUser(strUserName, strPID, strPassword) wrk.Users.Append usr

CreateUserAccountErr: Set usr = Nothing Set wrk = Nothing End Function

As with deleting a group, deleting a user is quite simple; just execute the Users collection's Delete method.

Public Sub DeleteUser(strUser As String) On Error Resume Next DBEngine(0).Users.Delete strUser End Sub

To rename a user account, you must delete the account, and then re-create it.

Was this article helpful?

0 0

Post a comment