Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



Listing All Groups and Users


Figure 28.2 have been replaced with combo boxes so the user can view and select from existing users and groups.

Figure 28.3. This form enables administrative users to maintain users, groups, and passwords.


Listing All Groups


The ListGroups function loops through each Group object in the Groups collection. As it loops, it uses the AddItem method of the combo box to add the name of the group to the combo box received as a parameter to the function. Chapter 9, "Advanced Form Techniques," covers the AddItem method in detail. Listing 28.13 gathers a list of existing groups in the workgroup.

Listing 28.13 Using the ListGroups Function to Create a List of All Groups

Function ListGroups(cboAny As ComboBox)
Dim cat As ADOx.Catalog
Dim grp As ADOx.Group
Set cat = New ADOx.Catalog
cat.ActiveConnection = CurrentProject.Connection
'Loop through each group in the Groups collection,
'Adding the name of each group to the
'combo box passed as a parameter
For Each grp In cat.Groups
cboAny.AddItem grp.Name
Next grp
End Function

Listing All Users


Listing all users is very similar to listing all groups, as shown in Listing 28.14.

Listing 28.14 Using the ListUsers Function to Create a List of All Users

Function ListUsers(cboAny As ComboBox)
Dim cat As ADOx.Catalog
Dim usr As ADOx.User
Set cat = New ADOx.Catalog
cat.ActiveConnection = CurrentProject.Connection
'Loop through each user in the Users collection,
'Adding the name of each user to the
'combo box passed as a parameter
For Each usr In cat.Users
cboAny.AddItem usr.Name
Next usr
End Function

This code loops through each User object in the Users collection. It adds the name of each user to the combo box.

Listing Users in a Specific Group


Sometimes it is necessary to print a list of users in a specific group. Listing 28.15 illustrates this process.

Listing 28.15 The Code in the cmdListUsers_Click Event That Lists All the Users In the Selected Group

Dim cat As ADOX.Catalog
Dim usr As ADOX.User
Dim strUsers As String
Set cat = New ADOX.Catalog
Set cat.ActiveConnection = CurrentProject.Connection
'Loop through each User object in the Users collection
'of the group selected in the cboGroupName combo box
For Each usr In cat.Groups(Me.cboGroupName.Value).Users
strUsers = strUsers & usr.Name & vbCrLf
Next usr
MsgBox strUsers
End Sub

The code loops through each User object in the Users collection of the group selected in the cboGroupName combo box. As it loops, it builds a string with the name of the user.

Determining Whether a User Is a Member of a Specific Group


You can easily determine whether a user is a member of a specific group. The process is illustrated in Listing 28.16.

Listing 28.16 The cmdIsUserInGroup_Click Event That Displays Whether the Selected User Is a Member of the Selected Group

Private Sub cmdIsUserInGroup_Click()
Dim cat As ADOX.Catalog
Dim usr As ADOX.User
Dim boolInGroup As Boolean
'If an error occurs, continue processing
On Error Resume Next
Set cat = New ADOX.Catalog
Set cat.ActiveConnection = CurrentProject.Connection
'Attempt to retrieve the Name property of the user selected
'in the Users combo box as part of the group selected in the
'Group combo box
boolInGroup = (cat.Groups(Me.cboGroupName.Value) _
.Users(Me.cboUserName.Value).Name = _
Me.cboUserName.Value)
'Display message with success or failure
If boolInGroup Then
MsgBox "User in Group"
Else
MsgBox "User Not in Group"
End If
End Sub

The code attempts to retrieve the Name property of the user selected in the cboUserName combo box as a member of the group selected in the cboGroupName combo box. If the user is not a member of the group, an error occurs. The code then compares the Name property to the value in the cboUserName combo box. The comparison returns True if the user is in the group and False if the user is not in the group. The appropriate message displays to the user.


/ 544