HandsOn Creating a User Account

This hands-on requires that you have performed all the steps listed under Custom Project 17-1.

1. Insert a new module and, in the module's Code window, enter the Create_ User procedure as shown below.

Sub Create_User()

Dim cat As ADOX.Catalog Dim conn As ADODB.Connection Dim strDB As String Dim strSysDb As String Dim strName As String

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

' 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 ' Create a new user and append it to ' the Users collection

Creating and Manipulating Databases with ADO

.Users.Append strName, "star" End With

MsgBox "Successfully created " & strName & " user account."


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

If Err.Number = -2147467259 Then

MsgBox strName & " user already exists."


MsgBox Err.Description End If

Resume ExitHere End Sub

Figure 17-12: Running the procedure in Hands-On 17-2 creates the PowerUser account. This user's group membership has not yet been established. To access this window, double-click the shortcut to the SpecialDb database on your desktop. Log in as Developer and type chapter17 for the password. Once the database opens, choose Tools | Security | User and Group Accounts.

0 0

Post a comment