Deleting a user from a Group using VBA

  • Thread starter Thread starter Chris Youlden
  • Start date Start date
C

Chris Youlden

I have an Acc2003 security enabled database containing the names of
students who log in to book facilities. They are all members of a Group
called "Students" giving them certain restricted permissions.

Occasionally it is necessary to suspend a student from booking
facilities, and I would like to achieve this by removing that user
account from the "Students" Group, but not deleting the user account itself.

Could anyone help me with some VBA code that would achieve this, and
also later to append that student back to the group by the
Administrator? (There is a secure form listing user names which the
administrator can view.)

TIA

Chris
 
I found this a while back when I was looking.

Public Sub DeleteUserFromGroup(strUser As String, _
strGroup As String)
' Remove a user from a group
' Source: Graham R Seach - MS Access MVP
'
http://groups.google.ca/group/micro...read/thread/3527785593af7279/b0d043a4d1dd6886
Dim wrk As DAO.Workspace

Set wrk = DBEngine(0)
On Error Resume Next

wrk.Users(strUser).Groups.Delete strGroup
wrk.Users.Refresh

Set wrk = Nothing
End Sub

Public Sub AddUser2Group(strUser As String, _
strGroup As String)
' Add a user to a group
' Source: Graham R Seach - MS Access MVP
'
http://groups.google.ca/group/micro...read/thread/3527785593af7279/b0d043a4d1dd6886
Dim wrk As DAO.Workspace
Dim usr As DAO.User
Dim grp As DAO.Group

Set wrk = DBEngine(0)
On Error Resume Next

'Create object references
Set grp = wrk.Groups(strUser)
Set usr = grp.CreateUser(strUser)

'Add the group to the user's Groups collection
grp.Users.Append usr
grp.Users.Refresh

Set usr = Nothing
Set grp = Nothing
Set wrk = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top