HandsOn Deleting a User Account

1. Insert a new module and, in the module's Code window, enter the Delete_ User procedure as shown below. Notice that this procedure takes as an argument the name of the user account you want to delete.

Sub Delete_User(UserName As String) Dim cat As ADOX.Catalog Dim conn As ADODB.Connection Dim strDB As String Dim strSysDb As String

On Error GoTo ErrorHandle strDB = "C:\BookProject\SpecialDb.mdb" strSysDb = "C:\BookProject\Security.mdw"

' Open connection to the database using ' the specified system database Set conn = New ADODB.Connection With conn

.Provider = "Microsoft.Jet.OLEDB.4.0" .Properties("Jet OLEDB:System Database") = strSysDb .Properties("User ID") = "Developer" .Properties("Password") = "chapter17" .Open strDB End With

' Open the catalog

Set cat = New ADOX.Catalog

With cat

.ActiveConnection = conn ' Delete user .Users.Delete UserName End With

MsgBox "The " & UserName & " was deleted."


Set cat = Nothing conn.Close Set conn = Nothing Exit Sub ErrorHandle:

If Err.Number = 3265 Then cat.Users.Append UserName, "star" Resume


MsgBox Err.Description Resume ExitHere

Part II

End If End Sub

2. To run the Delete_User procedure shown above, enter the following statement in the Immediate window and press Enter to execute it:

Delete_User "PowerUser"

0 0

Post a comment