Add Nearly Unlimited Text List Data to a Form

This function will add string text to a set number of fields on a form. The function allows you to set the limit of entries per field, as well as the number of fields per form.

You may have noticed that the "AppendToTextList" slows as over 100 entries are made in a single field. This way, you can add thousands of entries if desired. Duplicates are not added. Caveat - watch the number of fields and the field names, otherwise the UNK table may fill up and the database can be corrupted. However, this usually takes about 3000 field names in the database to occur, and many more (15,000+) in R5.
Function AddToFieldsList( doc As NotesDocument , FieldName As String ,
StringValue As String , _
NumPerField As Integer , NumFields As Integer ) As Variant

' This routine will add a StringValue to a series of FieldNameX items in a
' FieldName0 will contain up to NumPerField entries before FieldName1 is
' Result is True if the item was added, false otherwise.

On Error Goto ErrorOccured
Dim fldnum As Integer, foundit As Integer, tmpPosition As Integer, FieldNumber
As Integer
Dim tmpitem As NotesItem

AddToFieldsList = False
foundit% = 0
' First, search for the value in any of the current fields.
For fldnum% = 0 To NumFields%
Set tmpitem = doc.GetFirstItem( FieldName$ & Cstr( fldnum% ) )
If Not ( tmpitem Is Nothing ) Then
FieldNumber% = fldnum%
tmpPosition% = 0
' Double check that the field is not there but blank...
If tmpitem.Values( 0 ) <> "" Then
Forall itmvals In tmpitem.Values
If Ucase$( Trim$( itmvals ) ) = Ucase$( Trim$( StringValue$ ) ) Then
foundit% = 1
Exit Forall
End If
tmpPosition% = tmpPosition% + 1
End Forall
' The field was there but blank.
Exit For
End If ' Field was blank...
' tmpitem is nothing...
Exit For
End If
If foundit% = 1 Then Exit For
' Now, we add the data if needed.
If foundit% = 0 Then
If FieldNumber% <= NumFields% Then
' We can still add more fields or values to this field.
If tmpPosition% < NumPerField% Then
' We can add to the current field. Do so.
Set tmpitem = doc.GetFirstItem( FieldName$ & Cstr( FieldNumber% ) )
' It is possible that this field does not exist yet.
If tmpitem Is Nothing Then
Set tmpitem = doc.ReplaceItemValue( FieldName$ & Cstr( FieldNumber% ) ,
StringValue$ )
AddToFieldsList = True
tmpitem.IsSummary = False
Call tmpitem.AppendToTextList( StringValue$ )
AddToFieldsList = True
End If
Elseif FieldNumber% + 1 <= numFields% Then
' The current field is full. Create a new one.
Set tmpitem = New NotesItem( doc , FieldName$ & Cstr( FieldNumber% + 1 ) ,
StringValue$ )
AddToFieldsList = True
tmpitem.IsSummary = False
' We are full. No more can be added.
AddToFieldsList = False
Exit Function
End If ' The current field is empty.
' We are full. No more can be added.
AddToFieldsList = False
Exit Function
End If ' Where to add this item in the fields.
Else ' foundit% = 1
' File was found in the list, DO NOT mark it as an add.
AddToFieldsList = False
End If ' File was found

Exit Function
Messagebox "ERROR! - " & Error() & " (" & Cstr( Err() ) & ") Line:" & Erl()
Exit Function
End Function

This was first published in November 2000

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.