|
|
Unlike text or time fields, you need to close and reopen the uidoc to see changes that are made on rich text fields. You have to do something like:
Dim ws As New NotesUIWorkspace Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
Dim doc As NotesDocument Set doc = uidoc.Document ' make changes to back-end document's Rich Text fields here Call uidoc.Close Set uidoc = ws.EditDocument(True, doc)
Sub Postopen(Source As Notesuidocument)
'From Rich_Collette@siemon.com
'This routine copies a logo from a ListMaintenance form to this newly created LetterHead.
Dim ListDoc As NotesDocument
Dim doc As notesDocument
Dim db As NotesDatabase
Dim ListItem As notesRichTextItem
Dim docItem As NotesRichTextItem
Dim view As notesview
Dim workspace As New NotesUIWorkspace
'get the doc behind the new UIDoc
Set doc=source.document
'get the handle to the item that holds the Logo
Set docItem=doc.GetFirstItem("LogoRTF")
'check if Logo is already there from previous call to this routine
If (docItem.ValueLength > 10) Then ' For some reason the value is > 0 even if the item is empty.
Exit Sub
End If
'get handle to this database
Set db=doc.ParentDatabase
'form name isn't set on newly created docs, must set the value
doc.form="LetterWithLogo"
'get the "List" document that contains a logo in the RTFItems field
Set view = db.GetView( "List Maintainence" )
Set ListDoc = view.GetDocumentByKey( "LetterLogo", True )
'if you don't remove the item prior to seting its value, you get an error message about the types not being equivalent
Call doc.RemoveItem ("LogoRTF")
Set ListItem = ListDoc.GetFirstItem("RTFItems")
Set docItem = doc.CopyItem( ListItem, "LogoRTF" )
'close the uidocument that is currently open on the user's screen
Call source.close
'reopen the document
Set source = workspace.EditDocument( True, doc )
End Sub
Rich sent in another example that creates and displays a rich text field without requiring that the back-end doc get saved first:
Sub Initialize
'How to populate a new rich text field via backend classes and display without having to save the backend document
'
'If this is an existing saved document, then most of this is not needed, you just append to the existing RTF, close the UIDOC and edit the document
'similar to what is done at the very end of this code
'
'Created by Richard Collette, CLP Principal Developer
'rcollette@yahoo.com
'
'This demo needs a single form called "DemoDoc" - on the form place a field called "myRTF"
'
'Please note an actual application would test for "is Nothing" prior to using objects to insure they were instantiated.
'This was eliminated here to provide a more concise example
'
'Caveat: When closing and reopening a uidoc via its backend NotesDocument, the uidoc loses all notion that it is a response document and will save
'as a regular document. If you need a response document, you must capture the parent documentUNID (the selected document) and make the new
'document a response using the MakeResponse method.
Dim session As New NotesSession
Dim doc As NotesDocument
Dim tmpRTItem As NotesRichTextItem
Dim RTItem As NotesRichTextItem
Dim uiws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim styleHeadline As NotesRichTextStyle
Dim styleNormal As NotesRichTextStyle
Dim item As NotesItem
'compose the new document, or you can grab the current document that is on the workspace
Set uidoc=uiws.composeDocument("", "" , "DemoDoc")
If uidoc Is Nothing Then Exit Sub
Set uidoc=uiws.currentDocument
'get the backend document
Set doc=uidoc.document
'Create a temporary Rich Text Field that won't be saved
Set tmpRTItem= New NotesRichTextItem( doc , "RTFTemp")
tmpRTItem.saveToDisk=False
'create the style objects for setting text properties
Set styleHeadline=session.createRichTextStyle()
Set styleHeadline=session.createRichTextStyle()
Set styleNormal=session.createRichTextStyle()
styleHeadline.bold=True
styleHeadline.fontsize=14
styleNormal.bold=False
styleNormal.fontsize=10
'Add text, images, etc to the temporary rich text field
Call tmpRTItem.appendStyle(styleHeadline)
Call tmpRTItem.AppendText( "Headline" )
Call tmpRTItem.appendStyle(styleNormal)
Call tmpRTItem.AddNewLine(1)
Call tmpRTItem.AppendText( "Normal Text")
'**********************************The meat and potatoes of this demo starts here**********************************************************
'form name isn't stored on the composed NotesDocument until it is saved. Set the form name so we can re-edit the document and it will know what form to use.
doc.form="DemoDoc"
'don't prompt the user to save the document, set this back to "1" at the end of the code if you want the user to be able to save the document
doc.saveOptions="0"
'this causes two RTItems of the same name (RTFTemp) to be created on the back end document, they get combined into one only when the NotesDocument is saved, this makes RTF's difficult to work with
Call uidoc.close
'remove the RTF field to be displayed becuase it really isn't an RTF until the document is saved, another reason why RTFs are so difficult to work with
If (doc.isNewNote) Then
Call doc.removeItem("myRTF")
End If
'get the first of the two RTItems that were created during the close event, the second one is empty
Set tmpRTItem=doc.getFirstItem("RTFTemp")
'because the temporary RTF item was formated during UIDOC close process, we can now copy it to our actual document field.
'this code will not work without using a temporary RTFItem
Set RTItem = doc.CopyItem( tmpRTItem, "myRTF" )
'remove the temporary RTF Item from the backend document
Call doc.removeItem("RTFTemp")
'open the document in read mode and don't allow change to edit mode (any other mode possible)
Set uidoc=uiws.editDocument(True,doc)
Set doc=uidoc.document
'allow the user to save the document
doc.saveOptions="1"
'prevent SaveOptions from saving on the document
Set item=doc.getFirstItem("saveOptions")
item.saveToDisk=False
End Sub