Check if the Rich Text Field is empty or not

Posted on 2006-06-06
Last Modified: 2013-12-18
If doc.Attachment(0)="" Then

I've always used the above line to check if a field is filled in or not.

For Rich Text Field it doesn't work because I get an error "Variant doesn't contain a container"

I tried to check it with a Formula like @IsNull or @Contains but I didn't succeed.

@Attachments isn't good either, because there're more attachment fields but only one is required. If @Attachments returns 1, then I don't know if the required field is filled in or the user attached a file to another field which isn't required.
Question by:didier20
    LVL 46

    Accepted Solution

    Some ideas:
        http:Q_21226663.html "Checking if a Field is NULL!"
    LVL 22

    Expert Comment

    Hi didier20,

    Function IsRTFNull(rtfield As String) As Integer
        'This function tests a Rich Text field to see whether or not it
        'is null. It returns TRUE if the field is null, and returns
        'FALSE if the field is not null. It works even if the rich
        'text field contains a file attachment, doclink, or OLE
        'object but does not contain any 'text.

        On Error Goto Errhandle

        Dim workspace As New NotesUIWorkspace
        Dim uidoc As NotesUIDocument
        Set uidoc = workspace.CurrentDocument

        Call uidoc.ExpandAllSections
        'This is only needed if your field is in a section that may be closed when this executes

        Call uidoc.GotoField(rtfield)
        Call uidoc.SelectAll

        'The next line will generate a 4407 error message if the Rich Text Field is null

        Call uidoc.DeselectAll

        IsRTFNull = False

        Exit Function

        Select Case Err
        Case 4407
            'the DeselectAll line generated an error message, indicating that the rich text field does not contain anything
            If currentfield <> "" Then
                Call uidoc.GotoField(currentfield)
            End If
            IsRTFNull = True
            Exit Function
        Case Else
            'For any other error, force the same error to cause LotusScript to do the error handling
            Error Err
        End Select
    End Function

    Hope this helps,
    LVL 46

    Expert Comment

    by:Sjef Bosman
    Well, interesting... I'd say you had 20 minutes to follow my first link... :)

    Author Comment

    I think I should replace "rtfield" (in the above code ) with the field name in my db where the attachment is.

    Or should I replace the "currentfield"?

    It returns True or false but How can I see it? Message window or a field value will be changed?
    I pasted the Code but I notice no change.
    LVL 22

    Assisted Solution

    position the cursor in Globals - Declarations (at the end, if Declarations isn't empty) and paste the whole function.

    Then from the place you want to check if the RTF is empty call the function, like this:

        If IsRTFNull( "YourRTFfieldName" ) Then
            'whatever you want done
        End If

    Hope this helps,

    Author Comment


    It works like a charm.
    To be honest, I didn't believe that I can make it work after reading the below lines.

    (the exception would be rich text fields, which are just about impossible to check for emptiness. The rest you can do, usually, is check the .Text value of them, and see if it is a blank string, which could be a bad test if the field contains just an embedded Excel file or a bitmap image.
    LVL 46

    Expert Comment

    by:Sjef Bosman
    > ...just about impossible...
    so it's doable...

    LVL 22

    Expert Comment

    The problem here is that I didn't follow the link.
    I just posted the code from my Code library (
    Sorry Sjef (I could've explained earlier).

    I've used it here a couple of days ago:

    Bad mod...

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This is an old article, please see an updated version of this article, located here:
    IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the fileā€¦

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now