7.9. Managing Jet Security with ADO

Managing Access security in DAO was discussed in Chapter 6, and since the same methodology is used in ADO, we won't labor the point here. However, we will highlight the properties and methods available in ADO that aren't available in DAO.

The first thing to be aware of is that the ADO security objects are children of the Catalog object. For example, the Users and Groups collections are both accessed thus:

Dim cat As New ADOX.Catalog

cat.ActiveConnection = CurrentProject.Connection

Debug.Print cat.Groups(0).Name
Debug.Print cat.Users(0).Name

7.9.1. Creating Groups and Users

Once you've instantiated a Catalog object, you can create a new group in ADO by simply declaring its name as you append it to the Catalog object's Groups collection:

cat.Groups.Append "MyNewGroup"

To create a new user, all you need to do is to create a User object, set its name, and password, and then append it to the Catalog object's Users collection. The following example demonstrates just how easy it is to create a new group, a new user, and then add the user to a group.

Dim cat As ADOX.Catalog
Dim usr As ADOX.User

'Create the Catalog
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
'Create the new user
Set usr = New ADOX.User
usr.Name = "Doris Crockford"
usr.ChangePassword "", "sherbert_lemon"

To change the password at some later stage, just reissue the ChangePassword method using the following syntax:

userobject.ChangePassword oldpassword, ...

Get Access 2003 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.