Is there a definitive way to tell if a richtext field is empty? I have come across many routines (see sample below) but they all fail under one scenario: if the richtext field only contains a pasted graphic. Our app involves users pasting screen dumps into a richtext file. I can detect ‘emptyness’ if there’s ANYTHING else in the field, but if it only contains a paste graphic, every routine sees the field as empty. Any ideas? Thanks!
…Here are some routines I’ve tried…
Function IsrtfMT (doc As Notesdocument , FieldName As String) As Integer
Dim mbdcount As Integer,plaintext As String
Dim rtitem As Variant
mbdcount =0
Set rtitem = doc.GetFirstItem(fieldname)
If ( rtitem.Type = RICHTEXT ) Then
plainText = rtitem.GetFormattedText( False, 0 ) ' render the Rich item into text this gets all text values and ignores attachments/OLE
If Len(plaintext) < 1 Then
If Isarray(rtitem.EmbeddedObjects) Then
Forall o In rtitem.EmbeddedObjects ' loop through array of embedded objects in the rich text item
mbdcount=mbdcount+1 ' there is at least one emb object
End Forall
End If
End If
End If
If (mbdcount + Len(plaintext)) < 1 Then ' if there are no embedded objects AND there is no text also
IsrtfMT=1
Else
IsrtfMT=0
End If
End Function
Function IsRTitemEmpty( rtItem As NotesRichTextItem ) As Integer
Dim rtnav As NotesRichTextNavigator
Dim elemType(1 To 8) As Long
Dim iEmpty As Integer
Dim i As Integer
iEmpty = True
Set rtnav = rtItem.CreateNavigator
elemType(1) = RTELEM_TYPE_DOCLINK
elemType(2) = RTELEM_TYPE_FILEATTACHMENT
elemType(3) = RTELEM_TYPE_OLE
elemType(4) = RTELEM_TYPE_SECTION
elemType(5) = RTELEM_TYPE_TABLE
elemType(6) = RTELEM_TYPE_TABLECELL
elemType(7) = RTELEM_TYPE_TEXTPARAGRAPH
elemType(8) = RTELEM_TYPE_TEXTRUN
For i = 1 To 8 Step 1
If rtnav.FindFirstElement( elemType(i)) Then
iEmpty = False
Exit For
End If
Next
IsRTitemEmpty = iEmpty
End Function
Subject: Tell if a richtext field is empty?
You can check size of richtextitem. The empty has 94bytes.
Subject: RE: Tell if a richtext field is empty?
Not necessarily.
An “empty” RTF always contains the paragraph definitions that it inherits from the form. (Font, Size, Color, Bold, Hide-when formula, etc.) and so always has a non-zero size.
However, the value of that size depends on the form’s definition, and will vary from form to form, and could change if the form is modified.
Subject: RE: Tell if a richtext field is empty?
Yes you are right as I have written use 94 bytes rather then 0.
Subject: RE: Tell if a richtext field is empty?
I think Michal point was 94 is a “magic value” for your form and he just wants to make sure you’re aware of that.
I have one where the size is 210 when empty (just incase anyone is ever reading this thread in the future and thinks 94 would work in every case.)
Subject: RE: Tell if a richtext field is empty?
Regrettably, you can’t always tell this way, because if the rich text is split into multiple items (as often occurs) , you get the size of the first item, and depending what comes first in the rich text, this first item might be very short.
I’ve had to resort to scanning the DXL export of the document to tell for sure.
Subject: Tell if a richtext field is empty?
Hi BOB, You can try this code:
Function isRichtextPopulated( rti As NotesRichTextItem ) As Boolean
On Error Goto errHandler
isRichtextPopulated = False
Dim rtnav As NotesRichTextNavigator
Set rtnav = rti.CreateNavigator
' Check for text, doclink, or file attachment
'\\ Siddhartha Sen , 27th July 2007 , Kolkata, IN
'\\ Added: All types of elements as parameter to FindFirstElement ...previously only Doclink & File Attachment were added.
If Trim$( rti.Text ) <> "" _
Or rtnav.FindFirstElement( RTELEM_TYPE_DOCLINK ) _
Or rtnav.FindFirstElement( RTELEM_TYPE_FILEATTACHMENT ) _
Or rtnav.FindFirstElement( RTELEM_TYPE_OLE ) _
Or rtnav.FindFirstElement( RTELEM_TYPE_SECTION ) _
Or rtnav.FindFirstElement( RTELEM_TYPE_TABLE ) _
Or rtnav.FindFirstElement( RTELEM_TYPE_TABLECELL ) _
Or rtnav.FindFirstElement( RTELEM_TYPE_TEXTPARAGRAPH ) _
Or rtnav.FindFirstElement( RTELEM_TYPE_TEXTRUN ) Then
isRichtextPopulated = True
End If
finally:
Exit Function
errHandler:
isRichtextPopulated = False
Dim sErrMsg As String
Select Case Err
Case Else
sErrMsg = "Error #" & Err & Chr$(10) & Error$ & Chr$(10) & "Line #" & Erl & | in sub/function: "| & Lsi_info(2) & |"|
Msgbox sErrMsg, 16, "Unexpected error"
End Select
Resume finally
End Function
Subject: RE: Tell if a richtext field is empty?
Pritam,
I appreciate the tip, but this routine suffers from the same problem. If all you do is paste a graphic into the richtext field, your routine will say that the field is empty. Thank you for giving it a trying.
Subject: SOLUTION: Tell if a richtext field is empty?
Thanks to all who replied. I realized that a combination of all ideas would work in my case. The trick is that you have to apply them in the correct order and you need to know the default size of your particular richtext field when it’s blank. (Yes, that’s right. You cannot use this as a general routine and you must alter this routine if you alter any characteristics of the blank richtext field in your form.) But…it DOES detect an empty richtext field, so it solved my problem.
Here’s the code I settled on…
Function IsRTitemEmpty( rtItem As NotesRichTextItem ) As Integer
Dim lEmptyFieldLength As Long
lEmptyFieldLength = 162 ' <<-------- set for your specific rt field!!!!!!
Dim rtnav As NotesRichTextNavigator
Dim elemType(1 To 8) As Long
Dim i As Integer
'---- any text?
If Trim$( rtItem.Text ) <> "" Then
IsRTitemEmpty = False
Exit Function
End If
'— any detectible elements?
Set rtnav = rtItem.CreateNavigator
elemType(1) = RTELEM_TYPE_DOCLINK
elemType(2) = RTELEM_TYPE_FILEATTACHMENT
elemType(3) = RTELEM_TYPE_OLE
elemType(4) = RTELEM_TYPE_SECTION
elemType(5) = RTELEM_TYPE_TABLE
elemType(6) = RTELEM_TYPE_TABLECELL
elemType(7) = RTELEM_TYPE_TEXTPARAGRAPH
elemType(8) = RTELEM_TYPE_TEXTRUN
For i = 1 To 8 Step 1
If rtnav.FindFirstElement( elemType(i)) Then
IsRTitemEmpty = False
Exit Function
End If
Next
'-- rt field longer than normal?
If rtItem.ValueLength > lEmptyFieldLength Then
IsRTitemEmpty = False
Exit Function
End If
IsRTitemEmpty = True
End Function