I am having a horrible time trying to update a rich text field on a form that is already open. I followed the excellent advice listed in the “Tip” post (http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/dd507a5be7cc2e4285256eec005f56ef?OpenDocument) but when the code (which is in the QuerySave event) executes without the debugger active I get an “Object variable not set” error. Oddly enough, the code seems to have worked anyway, but the error message is annoying, and it causes the user to have to save again on exit.
Here’s the relevant part of the event code:
Dim wksp As New NotesUIWorkspace
Set doc = source.document
Set rtf = doc.GetFirstItem("InputHistory2")
If rtf Is Nothing Then
Set rtf = doc.CreateRichTextItem( "InputHistory2")
End If
Call rtf.appendtext(newInfo)
Call rtf.AddNewLine(1, False)
rtf.Update
doc.SaveOptions = "0" ' make it possible to close the document without a "do you want to save" prompt.
Call source.Close(True)
Set sourceNew = wksp.EditDocument(True, doc, , , , True)
Delete source
sourceNew.Document.RemoveItem("SaveOptions")
If strFieldname <> "" Then sourceNew.GotoField(strFieldname) ' return focus to field that was current before.
If I turn the debugger on, I get a different error. The code stops at the line:
Set sourceNew = wksp.EditDocument(True, doc, , , , True)
with the error “Specified command is not available from the workspace”.
This is not even an editable field that I’m updating - it’s computed rich text.
If I leave out everything after the rtf.Update call, the field doesn’t get updated at all, even after the document has been saved, closed and reopened.
Why is this so hard? Can anyone offer any help to make this work for me?
Subject: RE: Problem updating rich text in an open document
That was part of the code listed in the tip by Andre for updating the rich text in the front-end doc. I think what it does is close the ui doc (without prompting to save), then reopen it so the user will see the changes to the rich text field. The backend doc is still open and will get saved by the query-save (if the error didn’t stop it from executing).
But this error is making the save abort, so the user has to save again, which is annoying.
Subject: Problem updating rich text in an open document
Here’s some sample code that works for me.
Sub Click(Source As Button)
Set ws = New NotesUIWorkspace
Set s = New NotesSession
Set uidoc = ws.Currentdocument
Set currentdoc = uidoc.document
Set db = S.Currentdatabase
Set collect = ws.Picklistcollection(1, False, db.Server, _
Strleft(db.filepath, "\",5) + "\Ressources AISA.nsf", "ResByDate", _
"Réservations", "Sélectionnez la réservation correspondante")
If collect.count < 1 Then Exit Sub 'no document was selected or click on cancel
Set reservation = collect.Getfirstdocument
Set rtitem = currentdoc.GetFirstItem("VisitRoomReserv") 'only way to retain previous values
Call rtitem.AppendDocLink(reservation, "Cliquez sur le lien pour ouvrir la réservation")
Call currentdoc.Save(True, True)
currentdoc.SaveOptions = 0
currentkey = currentdoc.NoteID
Call uidoc.Close
Set currentdoc = db.GetdocumentByID(currentkey)
Set uidoc = ws.EditDocument(True, currentdoc)
End Sub
Don’t forget to remove your SaveOptions field in the Querymodechange event just in case, like:
Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
Dim doc As NotesDocument
Set doc = source.document
If doc.HasItem("SaveOptions") Then
Call doc.Removeitem("SaveOptions")
End If
Subject: RE: Problem updating rich text in an open document
Thanks - that helps a lot. It doesn’t get me there exactly because I’m doing things a little differently, but it gets me much closer. Very much appreciated.