Nun war es soweit, dass ich auch solch eine Lösung gebraucht habe.
Ich habe dabei Ulrichs Ansatz 1 mit eingebaut und ein Errorhandling integriert:
Function IsRichTextEmpty (doc As NotesDocument, strFieldName As String) As Integer
' This function checks if a rich text field is empty
' It returns 1 if the rt-item is empty and 0 if it is not.
'In case of problems: change the value "100" in the line "If rtItem.ValueLength > 100 Then" !
On Error Goto ErrorHandler
Dim iChecker As Integer
Dim rtItem As Variant
Dim iCount As Integer
Dim strPlaintext As String
iCount =0 ' initialize
Set rtItem = doc.GetFirstItem( strFieldName )
'---> ErrorHandling
IsRichTextEmpty = 0 'Default value
If rtItem Is Nothing Then Exit Function 'Does the item exist?
If Not ( rtItem.Type = RICHTEXT ) Then Exit Function 'Is the Item a RT-item?
'<---
'---> Check length of RTitem
If rtItem.ValueLength > 100 Then 'In case of problems: change the value "100" !
iCount=iCount+1
End If
'<---
'---> Check if the rtf includes text or embedded objects
strPlaintext = rtitem.GetFormattedText( False, 0 )
If Len(strPlaintext) < 1 Then
If Isarray(rtitem.EmbeddedObjects) Then
Forall o In rtitem.EmbeddedObjects
iCount=iCount+1
End Forall
End If
End If
'<----
'---> Result
If (iCount + Len(strPlaintext)) < 1 Then
IsRichTextEmpty=1
Else
IsRichTextEmpty=0
End If
'<---
ExitScript:
Exit Function
ErrorHandler:
Msgbox "Error: " & Err & " - " & Error$ & Chr(10) & Chr(10) _
& "Line: " & Erl & Chr(10) _
,48, "Error"
Resume ExitScript
End Function
gibt es einen Grund, warum du der Funktion das NotesDocument-Objekt + Feldnamen übergibts und nicht das Notes(RichText)Item selbst?
Nicht wirklich ::)
Siehst Du da einen Vorteil?
Die Function rufe ich übrigens über Postsave einer Maske auf und fülle das Feld "IsRTEmpty":
Sub Postsave(Source As Notesuidocument)
Dim doc As NotesDocument
Dim iEmptyChecker As Integer
Set doc = Source.Document
iEmptyChecker = IsRichtextEmpty(doc, "Remarks")
If iEmptyChecker = 1 Then
doc.IsRTEmpty = 1
Call doc.save(True,True)
Else
doc.IsRTEmpty = 0
Call doc.save(True,True)
End If
End Sub