Manage Security using code

  • Thread starter Thread starter Shaun E via AccessMonster.com
  • Start date Start date
S

Shaun E via AccessMonster.com

Right I seem to be getting ever closing to managing security using code. So
far changing passwords and adding new users. Thanks to all who have helped so
many on this site!!! Right now two more things I would like to accomplish
before I hope I will be able to leave security. Right they would be managing
users once they are on the system, ie changing the groups they are in and the
last thing would be deleting users from the system. Again any help here would
be very much appreciated.
 
Shaun:

Regarding deleting users, the following code sample is one example (cmbUsers
in a combo box with a list of user names):

Function DeleteUser()
Dim ws As Workspace
Dim sUser As String
Dim iResult As Integer

Set ws = DBEngine(0)

If Not IsNull(cmbUsers) And cmbUsers <> "" Then
sUser = cmbUsers
Else
MsgBox "Please specify a user to delete.", vbInformation, "Delete
User"
GoTo Function_Exit
End If

iResult = MsgBox("Are you sure you want to delete the user " & sUser &
"?", vbYesNo, "Confirm Deletion")

If iResult = vbNo Then GoTo Function_Exit

ws.Users.Delete sUser

Function_Exit:
Set ws = Nothing
Exit Function

End Function

Changing a users group is simply a combination of adding them to a new group
and deleting them from their existing group. For example:

Function ChangeGroup()
Dim grp as Group
Dim ws as Workspace
Dim usr as User

Set ws = DBEngine(0)

'Add to a new group
Set grp = ws.Groups("NewGroupName")
grp.Users.Append grp.CreateUser("UserName")

'Delete from existing group
Set usr = ws.Users("UserName")
usr.Groups.Delete "OldGroupName"

Set ws = Nothing
Set grp = Nothing
Set usr = Nothing

End Function

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Right I seem to be getting ever closing to managing security using code. So
far changing passwords and adding new users. Thanks to all who have helped
so
many on this site!!! Right now two more things I would like to accomplish
before I hope I will be able to leave security. Right they would be managing
users once they are on the system, ie changing the groups they are in and
the
last thing would be deleting users from the system. Again any help here
would
be very much appreciated.
 
Back
Top