2008年8月19日 星期二

如何得資料庫中到某個role中所有人員名單(陣列)

取得資料庫中到某個role中所有人員名單函數
------------------------------------

Function getRoleUsersOnDB( RoleName As String , ndb As notesDatabase ) As Variant


%REM
功能:取得某角色在資料庫上的所有使用者名稱
參數:
RoleName:要查詢的角色名稱
ndb:要查詢的資料庫物件
傳回值:符合RoleName的所有人員陣列
%END REM

Dim tacl As NotesACL
Dim taclEntry As NotesACLEntry
Dim tmpArray As Variant , hasRolesInACL As Boolean
Dim arr1 As Variant, i As Integer

On Error Goto SubHander

hasRolesInACL = False
Redim arr1(0) As String
getRoleUsersOnDB = arr1

If RoleName = "" Then Exit Function

If ndb Is Nothing Then Exit Function


If Not( ndb.IsOpen ) Then If Not( ndb.Open( ndb.Server , ndb.FilePath ) ) Then Exit Function

Set tacl = ndb.ACL

For i = Lbound( tacl.Roles ) To Ubound( tacl.Roles )
If Lcase( tacl.Roles( i ) ) = Lcase( RoleName ) Then
hasRolesInACL = True
RoleName = tacl.Roles( i )
Exit For
End If
Next

If hasRolesInACL Then
Set taclEntry = tacl.GetFirstEntry
While Not( taclEntry Is Nothing )
If taclEntry.Isroleenabled( RoleName ) Then
If Not Isarray( tmpArray ) Then
Redim tmpArray( 0 ) As String
Else
Redim Preserve tmpArray( Ubound( tmpArray ) + 1 ) As String
End If
tmpArray( Ubound( tmpArray ) ) = taclEntry.Name
End If
Set taclEntry = tacl.GetNextEntry( taclEntry )
Wend
End If
getRoleUsersOnDB = tmpArray

Exit Function
SubHander:

Exit Function
End Function
---來源臭氧層 Notes 討論區

沒有留言: