Validation of rich text field on the UI poses a tricky situation, particularly when it is required to check if any attachments have been added to the field. This happens because the LotusScript doesn't get a handle to the embedded objects in a rich text field until the UI document is saved to the backend document. Thanks to the enhanced 'refresh' method of NotesUIDocument class in R5, this tricky problem can be solved with some simple code.
Here is the 'test' code and the steps to carry out the test...
- Add a button to a form that contains a rich text field named 'Body'
- Attach the following code to the button.
- Save the form and preview in Notes client.
- When you click on the button, it should pop-out a message indicating the number of attachments in the Body field.
Dim ws As New NotesUIWorkspace Dim uidoc As NotesUIDocument Dim doc As NotesDocument Set uidoc = ws.CurrentDocument Set doc = uidoc.document uidoc.refresh True '<= here's the hero! The 'True' parameter 'transfers' all rich text items to the back-end document. Dim rtitem As Variant Dim embedObjs As Variant Set rtitem = doc.getFirstItem("Body") embedObjs = rtitem.embeddedObjects Msgbox "There are " + Cstr(Ubound(embedObjs) + 1) + " attachments in 'Body' field"