HandsOn Deleting a Group Account

1. Insert a new module and, in the module's Code window, enter the

Delete_Group procedure as shown below. Notice that this procedure takes as an argument the name of the group account you want to delete.

Sub Delete_Group(GroupName As String) Dim conn As ADODB.Connection Dim cat As ADOX.Catalog 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 group .Groups.Delete GroupName End With

MsgBox "The " & GroupName & " group was deleted."


Set cat = Nothing conn.Close

Set conn = Nothing

Creating and Manipulating Databases with ADO

Exit Sub ErrorHandle:

If Err.Number = 3265 Then cat.Groups.Append "Masters" Resume


MsgBox Err.Description Resume ExitHere End If End Sub

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

Delete_Group "Masters"

0 0

Post a comment