Nach parent.Authors zu suchen, ist nicht zu empfehlen. In einer zufällig ausgewählten Mail in meiner Maildatenbank existiert dieses Feld nicht. Besser ist m.E. zu prüfen, ob Items vorhanden sind
If Not Isarray (Parent.Items) Then
'Dokument ist gelöscht
End If
In Deinem Script wirst Du auf einen Fehler laufen, wenn Du tatsächlich ein Dokument änderst. Deine Ansicht ist gefiltert nach Vorhandensein des Items $REF. Änderst Du das aktuelle Dokument, hat dieses nicht mehr das Item und bei
Set Doc = Ansicht.GetNextDocument(doc)
bekommst Du den Hinweis, dass das Dokument doc nicht in der Ansicht enthalten ist. Eine Collection ist da mein persönlicher Favorit, alternativ musst Du mit mehreren Document-Objekten hantieren oder ein Aktualisieren-Flag in der Ansicht setzen, was aber nachher wieder zurückgesetzt werden muss.
EDIT: noch ein Nachsatz zur besseren Wartbarkeit
Anstelle von
While Not Doc Is Nothing
If Doc.Form(0) = "Memo" Then
DocUNID = doc.ParentDocumentUNID
Set Parent = db.GetDocumentByUNID(DocUNID)
If Parent Is Nothing Then
Call doc.RemoveItem( "$Ref" )
Call doc.Save( True, True )
End If
Else
If Doc.Form(0) = "Reply" Then
DocUNID = doc.ParentDocumentUNID
Set Parent = db.GetDocumentByUNID(DocUNID)
If Parent Is Nothing Then
Call doc.RemoveItem( "$Ref" )
Call doc.Save( True, True )
End If
End If
End If
Set Doc = Ansicht.GetNextDocument(doc)
Wend
würde ich die Bedingung mit einem OR schreiben, dann hast Du den Schleifeninhalt nur einmal
While Not Doc Is Nothing
If Doc.Form(0) = "Memo" Or Doc.Form(0) = "Reply" Then
DocUNID = doc.ParentDocumentUNID
Set Parent = db.GetDocumentByUNID(DocUNID)
If Parent Is Nothing Then
Call doc.RemoveItem( "$Ref" )
Call doc.Save( True, True )
End If
End If
Set Doc = Ansicht.GetNextDocument(doc)
Wend
Das aber nur am Rande ...
Ehrlich gesagt hatte ich ja gedacht den Code nicht posten zu müssen...sei´s drum
Ansicht "Antworten" enthält die folgende Selektionsformel - damit nicht auch noch dort etwas schief geht:
SELECT Form = "Antwort" & @IsResponseDoc
Dann der eigentliche Code für´s Umwandeln:
Dim s As New NotesSession
Dim db As NotesDatabase
Set db = s.CurrentDatabase
Dim v As NotesView
Set v = db.GetView("Antworten")
Dim it As notesitem
Dim work_doc As notesdocument
Dim resp_doc As NotesDocument
Dim par_doc As NotesDocument
Set resp_doc = v.GetFirstDocument
While Not(resp_doc Is Nothing)
Set work_doc = resp_doc
Set resp_doc = v.GetnextDocument(resp_doc)
Set par_doc = db.GetDocumentByUNID(work_doc.ParentDocumentUNID)
If par_doc.Authors(0) = "" Then
Set it = work_doc.GetFirstItem("$Ref")
Call it.Remove
work_doc.Save True, False
End If
Wend