' This sub adds a user to a group, but does it in a way
' that allows very large groups. Because Notes stores group members in
' text lists, and text lists can have only 15K bytes in them, simple groups
' are limited to around 1000 members. To have more members than that,
' the group must be broken into a number of other groups, which are
' then referenced as members of a master group.
' This sub handles all of that complexity. The group name passed in
' is the name of the master group, and this sub will handle the creation
' and populating of the sub-groups as needed. The sub-groups will
' be named by appending numbers to the master group name, and will
' have slightly more than 10K bytes of members in them.
Sub AddUserToGroup( Byval fullname As String, Byval group As String, nab As
' Load up our static groups view
Dim groups As NotesView
Set groups = nab.GetView( "Groups" )
Dim groupMainDoc As NotesDocument
Set groupMainDoc = groups.GetDocumentByKey( group )
Dim saveGroupMainDoc As Integer
saveGroupMainDoc = False
If groupMainDoc Is Nothing Then
Set groupMainDoc = New NotesDocument( nab )
groupMainDoc.Form = "Group"
groupMainDoc.ListName = group
groupMainDoc.Members = group & " 1"
groupMainDoc.GroupType = "0"
Call groupMainDoc.ComputeWithForm( False, False )
saveGroupMainDoc = True
Dim groupMainMembers As NotesItem
Set groupMainMembers = groupMainDoc.GetFirstItem( "Members" )
' Find last subgroup entry in the members list
Dim subGroup As String
subGroup = ""
Forall s In groupMainMembers.Values
If Left$( s, Len( group ) ) = group Then
subGroup = s
' Open the subgroup, and keep trying until we find one with room
Dim groupNum As Integer
groupNum = 0
' Which subgroup was the last one
If subGroup <> "" Then
groupNum = Val( Right( subGroup, Len( subGroup ) - Len( group ) - 1 )
groupNum = 1
subGroup = group & " 1"
Dim groupSubDoc As NotesDocument
Set groupSubDoc = groups.GetDocumentByKey( subGroup )
If groupSubDoc Is Nothing Then
' Create a new subgroup document
Set groupSubDoc = New NotesDocument( nab )
groupSubDoc.Form = "Group"
groupSubDoc.ListName = subGroup
groupSubDoc.GroupType = "0"
Call groupSubDoc.ComputeWithForm( False, False )
' Add it to the main group if needed
If Not groupMainMembers.Contains( subGroup ) Then
Call groupMainMembers.AppendToTextList( subGroup )
saveGroupMainDoc = True
' See if the subgroup still has room, if so, we've found our subgroup
Dim groupSubMembers As NotesItem
Set groupSubMembers = groupSubDoc.GetFirstItem( "Members" )
If groupSubMembers.ValueLength < 10000 Then
' If no room, try the next one
groupNum = groupNum + 1
subGroup = group & " " & groupNum
' Finally: add the user to the subgroup
Call groupSubMembers.AppendToTextList( fullname )
Call groupSubDoc.Save( False, True )
If saveGroupMainDoc Then
Call groupMainDoc.Save( False, True )
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.