I currently have a piece of lotus script which initially deletes response documents before deleting the current uidoc. This all works OK, but I then need to close the window. When I attempt that it gets the error ‘NotesUIDocument object is no longer valid’. I understand why, but how do I get around it. The code follows:Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim user As NotesName
Dim orgdoc As NotesDocument
Dim db As NotesDatabase
Dim view As NotesView
Set uidoc = ws.CurrentDocument
Set db = session.CurrentDatabase
Set orgdoc = uidoc.Document
Dim myOrg As String
myOrg = uidoc.FieldGetText(“OrgName”)
Dim cont_coll As NotesDocumentCollection
Dim cont_resp As NotesDocument
Set cont_coll = orgdoc.Responses
Set cont_resp = cont_coll.GetFirstDocument
While Not ( cont_resp Is Nothing )
Dim act_coll As NotesDocumentCollection
Dim act_resp As NotesDocument
Set act_coll = cont_resp.Responses
Set act_resp = act_coll.GetFirstDocument
While Not ( act_resp Is Nothing )
Call act_coll.RemoveAll(True)
Wend
Set cont_resp = cont_coll.GetNextDocument ( cont_resp )
The DeleteDocument method in the Hlep Screen works:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
hm = collection.Count
For j = 1 To hm
Set doc = collection.GetNthDocument(j)
Call doc.Remove(False)
Next
This deletes a saved document when it is open and in edit mode.
Create an Agent (LotusScript) and run it from there.
Actually, I didn’t know about the DeleteDocument method. You might want to try closing it before deleting the document, maybe it will still be available, but I doubt it. Otherwise, I suggest you try the old method that worked before DeleteDocument came along, which is along these lines:
(From memory, may not be 100% accurate)
Dim sUNID as string
Dim doc as NotesDocument
Set doc = uidoc.Document
sUNID = doc.UniversalID
Call uidoc.Close
Delete uidoc
Set doc = db.GetDocumentByUNID( sUNID )
Call doc.Remove(True)
The key here is the Delete uidoc statement. It removes any references to uidoc and anything created from it, and enables you to safely delete the document if you then get a handle to it using the unid.