Field changes not saving

This one had me going!!

I had a view that I used the QueryOpenDocumnet to update a document with the name of the user that last opened the document.

Sub Queryopendocument(Source As Notesuiview, Continue As Variant)

On Error Goto ErrorHandler

Set sdc = sview.Documents

Set sdoc = sdc.GetFirstDocument



sdoc.LastReadBy = session.username

sdoc.LastReadDate = Now

sdoc.LastReaddView = sview.ViewName

Call sdoc.Save(True,True)

End If

Exit Sub

ErrorHandler:

Print   Error$ & " (" & Cstr(Err) & ")  at line # " & Cstr(Erl)

Resume Next

End Sub

This all worked fine!

BUT if you would edit the document, save and close it. The view would show the changes but the next time you opened the document the changes would be gone.

The problem seems to be that the save in the view is being load to the disk after the document save overwriting the changes.

Hope this helps save you the days looking for it.

Subject: Field changes not saving

The problem is that your code …

Set sdc = sview.Documents

Set sdoc = sdc.GetFirstDocument

… is getting a reference to the document from the view, and updating it. Meanwhile, you have a second reference that’s open in the UI in the client, that is a copy of the view’s document before you modified it.

You need to use the Source parameter in the QueryOpenDocument to ensure that you are updating the document that’s open, and not go out to get a second reference.

Background : When you open a document, you are working with a copy in memory, that’s only writted back to the database when saved. So in effect, you took one copy (the open document) then took a second copy (the sdoc). The changes you made to sdoc, and saved to the database, were not made to the open copy.