Task:
Have a Notes client-based form with a Rich Text Field (RTF) requiring validation.
Need to check if has text, embedded objects, or attachments.
Note:
- This does Not check a V2 attachment which is outside a RTF
- Since NotesRichTextItem extends (inherits) from NotesItem, all the properties and methods of NotesItem are available, as well.
Empty Check:
There are two ways to check for an empty RTF.
1. Check the NotesItem.Text to empty string
2. Check the NotesItem.ValueLength
Function IsRTFEmpty(uiDoc As NotesUIDocument, fldNm As String, minLength as Long) As Integer
' returns 0 for false, or error, and 1 for true/empty
' uiDoc - UI document front-end
' fldNm - the name of the RTF
' minLength - minimum length of the value to not be null. e.g. 200
Dim docFld As NotesItem
Dim doc As NotesDocument
Dim docFldLength As Long
On Error Goto FErrorHandler
IsRTFEmpty = 0
If (minLength < 0) Then
minLength = 0
End If
If (uiDoc is Nothing) Then
' abort
Print (IsRTFEmpty) Document was not passed (Nothing)."
Exit Function
End If
Set doc= uiDoc.Document
If (doc is Nothing) Then
' is doc new?
Print (IsRTFEmpty) Back-end Document could not be loaded (Nothing)."
Exit Function
End If
Set docFld = doc.GetFirstItem(fldNm)
If (docFld Is Nothing) Then
' abort, field not found
Print (IsRTFEmpty) Field, " & fldNm & ", not found."
Exit Function
End If
docFldLength = docFld.ValueLength
If ( docFldLength > minLength ) Then
IsRTFEmpty= 1
End If
FExit:
Exit Function
FErrorHandler:
Print "(IsRTFEmpty) Unexpected error: " & Cstr(Err) & ", line: " & Cstr(Erl) & ", Error: " & Error$ & "."
Resume FExit
End Function
Type of RTF Field Content:
Notes:
- The following checks for all the types of content including just text, but you can test for just one or a different subset by simply updating the if/then conditions.
Function IsRTFTypesEmpty(uiDoc As NotesUIDocument, fldNm As String) As Integer
' returns 0 for false (or error), and 1 for true/empty
Dim docFld as NotesItem ' the RTF field
Dim docRTFNav As NotesRichTextNavigator ' navigator for docFld
On Error Goto FErrorHandler
IsRTFTypesEmpty = 0
' tests
If (uiDoc is Nothing) Then
' abort
Print (IsRTFTypesEmpty) Document was not passed (Nothing)."
Exit Function
End If
Set doc= uiDoc.Document
If (doc is Nothing) Then
' is doc new?
Print (IsRTFTypesEmpty) Back-end Document could not be loaded (Nothing)."
Exit Function
End If
' perform check
Set docFld = doc.GetFirstItem(fldNm)
If (docFld Is Nothing) Then
' abort, field not found
Print (IsRTFTypesEmpty) Field, " & fldNm & ", not found."
Exit Function
End If
If ( docRTFNav.FindFirstElement(RTELEM_TYPE_DOCLINK) Or _
docRTFNav.FindFirstElement(RTELEM_TYPE_FILEATTACHMENT) Or _
docRTFNav.FindFirstElement(RTELEM_TYPE_OLE)) Or _
docRTFNav.FindFirstElement(RTELEM_TYPE_SECTION) Or _
docRTFNav.FindFirstElement(RTELEM_TYPE_TABLE) Or _
docRTFNav.FindFirstElement(RTELEM_TYPE_TABLECELL) Or _
docRTFNav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Or _
docRTFNav.FindFirstElement(RTELEM_TYPE_TEXTRUN) ) Then
' found content, leave IsRTFTypesEmpty = 0
Exit Function
Else
' RTF special types content not found, check for plain text
If Not (docFld.Text = "") Then
' found content, leave IsRTFTypesEmpty = 0
Exit Function
End If
' types and text content not found, return empty
IsRTFTypesEmpty = 1
End If
FExit:
Exit Function
FErrorHandler:
Print "(IsRTFEmpty) Unexpected error: " & Cstr(Err) & ", line: " & Cstr(Erl) & ", Error: " & Error$ & "."
Resume FExit
End Function
previous page
|