Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete a User From Security Using Code

Status
Not open for further replies.

Lightning

Technical User
Jun 24, 2000
1,140
AU
I'm developing a database for a client with a steady rate of staff turnover. I've implemented Access security and set up a form where the system "administrator" can add new users to the security file. This runs a function which updates the .mdw file through code. So far so good.

However, nowhere can I find any reference or examples of how to delete users from the .mdw file through code. Is the process so basic that I'm overlooking it completely, or does everyone write their own function when they need it? Can anyone point me in the right direction, or does anyone have a working function or code sample to do this.

The "administrator" position is one of the positions which can turn over fairly regularly, so I cannot guarantee that the occupant will have more than a basic knowledge of Access. Because of this, I do not want to give them access to the Security option on the Tools menu.

Any help would be greatly appreciated. Thanks in advance

Lightning [sig][/sig]
 
This is from "Mastering ACCESS 97 Development 2nd Edition" by Alison Balter

It is a function that is called from a command button on a form used to maintain Users by Code

Function Remove Users()
On Error GoTo RemoveUsers_Err

Dim wrk as Workspace

RemoveUsers = True

Set wrk = DBEngine.Workspaces(0)
wrk.Users.Delete Me!txtUserName ' name of textbox on the form

RemoveUsers_Exit
Set wrk = Nothing
Exit Function

RemoveUsers_Err:
If Err.Number = 3265 then
MsgBox "User Not Found"
Else
MsgBox "Error # " & Err.Number & " : " & Err.Description
End If

RemoveUsers = False
Resume RemoveUsers_Exit

End Function


The code attached to the Command Button is as follows

Private Sub cmdRemove_Click()
Dim fSuccess as Boolean
If IsNull(Me!txtUserName) then
MsgBox "You Must Fill In User Name Before Proceeding"
Else
fSuccess = RemoveUsers()
If fSuccess then
MsgBox "User Removed Successfully"
Else
MsgBox "User Not Removed"
End If
End If
End Sub

HTH

PaulF [sig][/sig]
 
This is exactly what I was after. It's plugged in and working perfectly.

Thanks for the source. Looks like another book for the library.

Many Thanks Paul

Lightning [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top