I have one editable RT field (fFollowUpTextToAdd) and one computed RT field (fFollowUp). I want to add data in 1’st field, hit the button and add those data in 2’nd RT field (computed, so users can not change the content). Everything works gread, only attachments not. If I click the attachment icon in computed RT field, I receive ‘Note Item not found error’.
I suppose, this has something to do with the RT refresh (it seems, that attachment has not been saved), but if I call uidoc.save, or doc.save just after I compose the final RT field, nothing is changed and I still receive the same error.
Something similar can be found here: http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/079017449918b7528525719900576d8e?OpenDocument, but I don’t see any helpful answer in this post.
Here is the code without any changes !!!
Sub Click(Source As Button)
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim uidocNew As NotesUIDocument
Dim doc As NotesDocument
Dim username As NotesName
Dim richStyleNormal As NotesRichTextStyle
Dim richStyleBold As NotesRichTextStyle
Dim rtnav As NotesRichTextNavigator
Dim rtitemHistory As notesrichtextitem
Dim rtitemToInsert As notesrichtextitem
Dim rtitemTemp1 As NotesRichTextItem
Dim rtitemTemp2 As NotesRichTextItem
Dim hdr As String
Dim recipients As Variant
Dim cc As Variant
Dim subj As String
REM some declarations are global
Const FLD_RECIPIENTS = "fTaskLeader"
Const FLD_CC = "cpyTo"
Const FLD_RTITEM_TEMP1= "tempRTItem1"
Const FLD_RTITEM_TEMP2 = "tempRTItem2"
Const FLD_HISTORY = "fFollowUp" 'history field
Const FLD_TEXT_TO_ADD = "fFollowUpTextToAdd" 'text you want to add in history field
REM Compose title
Set userName = session.CreateName(session.UserName)
hdr = "("+Cstr(Date)+", "+Cstr(Time)+", "+userName.Common+")"
REM define the rich text font styles
REM first bold style
Set richStyleBold = session.CreateRichTextStyle
richStyleBold.NotesFont = FONT_COURIER
richStyleBold.FontSize = 10
richStyleBold.Bold = True
richStyleBold.NotesColor = COLOR_DARK_BLUE
REM second the normal style
Set richStyleNormal = session.CreateRichTextStyle
richStyleNormal.NotesFont = FONT_COURIER
richStyleNormal.FontSize = 10
richStyleNormal.Bold = False
Set uidoc = ws.CurrentDocument
REM refresh the RT fields ..
Call uidoc.Refresh(True)
Set doc = uidoc.Document
REM create and get all necessary rich text items
Set rtitemHistory = doc.GetFirstItem(FLD_HISTORY)
Set rtitemToInsert = doc.GetFirstItem(FLD_TEXT_TO_ADD)
While Not doc.HasItem(FLD_RTITEM_TEMP1)
Set rtitemTemp1 = doc.CreateRichTextItem(FLD_RTITEM_TEMP1)
Wend
While Not doc.HasItem(FLD_RTITEM_TEMP2)
Set rtitemTemp2 = doc.CreateRichTextItem(FLD_RTITEM_TEMP2)
Wend
REM prepare the header data you want to insert in the history field
Call rtitemTemp1.AppendStyle(richStyleBold)
Call rtitemTemp1.AppendText(hdr+": ")
Call rtitemTemp1.AppendStyle(richStyleNormal)
Call rtitemTemp1.AddNewLine(2)
Call rtitemTemp1.AppendRTItem(rtitemToInsert)
Call rtitemTemp1.AddNewLine(2)
REM remember the content of rtitemHistory first
Call rtitemTemp2.AppendRTItem(rtitemHistory)
REM We need to clear the history in the history field. To clear the field, first delete it and create from scratch
While doc.HasItem(FLD_HISTORY)
Call doc.RemoveItem(FLD_HISTORY)
Wend
REM then create the history field from scratch
Set rtitemHistory = doc.CreateRichTextItem(FLD_HISTORY)
REM bring the RT field to front, so I can read it programatically
Call uidoc.Refresh(True)
REM first add to history the new data (they will be on the top of the history - WHICH IS A DEMAND)
Call rtitemHistory.AppendRTItem(rtitemTemp1)
REM then add data, which have been in history field before
Call rtitemHistory.AppendRTItem(rtitemTemp2)
REM delete the temporary rich text fields. We don't need them any more
While doc.HasItem(FLD_RTITEM_TEMP1)
Call doc.RemoveItem(FLD_RTITEM_TEMP1) ' Wipe out the temp field
Wend
While doc.HasItem(FLD_RTITEM_TEMP2)
Call doc.RemoveItem(FLD_RTITEM_TEMP2) ' Wipe out the temp field
Wend
REM Call uidoc.Refresh(True)
Call rtitemHistory.Update
REM close and reopen the document, so the RT changes are updated on the fly
doc.SaveOptions = "0"
Call uidoc.Close(True)
Set uidocNew = ws.EditDocument(True, doc, , , , True)
Call uidocNew.Reload()
Call uidocNew.FieldSetText(FLD_TEXT_TO_ADD,"")
Delete uidoc
uidocNew.Document.RemoveItem("SaveOptions")
End Sub