S
Stuart Jack via AccessMonster.com
Hi
I have a database in which I have applied Access security, I have created a
form which the admin user can create new users and they are added to the
Users group - code below.
Code:
----------------------------------------------------------------------------
Public Function sCreateUser(ByVal strUser As String, ByVal strPID As String,
Optional varPwd As Variant) As Integer
' Create a new user and add them to the users group
' Returns True on success, False if already exists
Dim db As Database
Dim ws As Workspace
Dim usr As User
Dim grpUsers As Group
Dim strSQL As String
'If the password isn't supplied, make sure you
' pass an empty string for the password argument
If IsMissing(varPwd) Then varPwd = ""
Set ws = DBEngine.Workspaces(0)
ws.Users.Refresh
On Error Resume Next
' Check to see if the user already exists by using inline
' error handling to trap any errors caused by setting
' a reference to a possibly non-existent user
strUser = ws.Users(strUser).Name
If Err.Number = 0 Then
MsgBox "The user you are trying to add already exists.", _
vbInformation, "Can't Add User"
sCreateUser = False
Else
' go ahead and create user account
Set usr = ws.CreateUser(strUser, strPID, varPwd)
ws.Users.Append usr
ws.Users.Refresh
' now add the user to the Users group
Set grpUsers = ws.Groups("Users")
Set usr = grpUsers.CreateUser(strUser)
grpUsers.Users.Append usr
grpUsers.Users.Refresh
sCreateUser = True
End If
End Function
I would like to be able to create another form which has a listbox of users
names in the Users group from which the Admin db can then select a user name
to remove from the system. I can enumerate the users by the using the code
below, but I am not too good at getting this into a listbox or combo box.
Code:
------------------------------------------------------------------------------
-
Function EnumGrpsNUsers()
Dim grp As Group
Dim usr As User
For Each usr In DBEngine(0).Users
Debug.Print usr.Name
For Each grp In usr.Groups
Debug.Print vbTab; grp.Name
Next
Next
End Function
Can anyone suggest where I start please.
Thanks
Stuart
I have a database in which I have applied Access security, I have created a
form which the admin user can create new users and they are added to the
Users group - code below.
Code:
----------------------------------------------------------------------------
Public Function sCreateUser(ByVal strUser As String, ByVal strPID As String,
Optional varPwd As Variant) As Integer
' Create a new user and add them to the users group
' Returns True on success, False if already exists
Dim db As Database
Dim ws As Workspace
Dim usr As User
Dim grpUsers As Group
Dim strSQL As String
'If the password isn't supplied, make sure you
' pass an empty string for the password argument
If IsMissing(varPwd) Then varPwd = ""
Set ws = DBEngine.Workspaces(0)
ws.Users.Refresh
On Error Resume Next
' Check to see if the user already exists by using inline
' error handling to trap any errors caused by setting
' a reference to a possibly non-existent user
strUser = ws.Users(strUser).Name
If Err.Number = 0 Then
MsgBox "The user you are trying to add already exists.", _
vbInformation, "Can't Add User"
sCreateUser = False
Else
' go ahead and create user account
Set usr = ws.CreateUser(strUser, strPID, varPwd)
ws.Users.Append usr
ws.Users.Refresh
' now add the user to the Users group
Set grpUsers = ws.Groups("Users")
Set usr = grpUsers.CreateUser(strUser)
grpUsers.Users.Append usr
grpUsers.Users.Refresh
sCreateUser = True
End If
End Function
I would like to be able to create another form which has a listbox of users
names in the Users group from which the Admin db can then select a user name
to remove from the system. I can enumerate the users by the using the code
below, but I am not too good at getting this into a listbox or combo box.
Code:
------------------------------------------------------------------------------
-
Function EnumGrpsNUsers()
Dim grp As Group
Dim usr As User
For Each usr In DBEngine(0).Users
Debug.Print usr.Name
For Each grp In usr.Groups
Debug.Print vbTab; grp.Name
Next
Next
End Function
Can anyone suggest where I start please.
Thanks
Stuart